Merge branch 'rs/maint-dir-strbuf' into rs/dir-strbuf
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2012 16:43:40 +0000 (09:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2012 16:43:40 +0000 (09:43 -0700)
By RenĂ© Scharfe
* rs/maint-dir-strbuf:
  dir: convert to strbuf

1  2 
dir.c

diff --cc dir.c
--- 1/dir.c
--- 2/dir.c
+++ b/dir.c
@@@ -968,34 -955,34 +962,35 @@@ static int read_directory_recursive(str
  {
        DIR *fdir = opendir(*base ? base : ".");
        int contents = 0;
-       char path[PATH_MAX + 1];
 +      struct dirent *de;
++      struct strbuf path = STRBUF_INIT;
  
 -      if (fdir) {
 -              struct dirent *de;
 -              struct strbuf path = STRBUF_INIT;
 -
 -              strbuf_add(&path, base, baselen);
 -
 -              while ((de = readdir(fdir)) != NULL) {
 -                      switch (treat_path(dir, de, &path, baselen, simplify)) {
 -                      case path_recurse:
 -                              contents += read_directory_recursive
 -                                      (dir, path.buf, path.len, 0, simplify);
 -                              continue;
 -                      case path_ignored:
 -                              continue;
 -                      case path_handled:
 -                              break;
 -                      }
 -                      contents++;
 -                      if (check_only)
 -                              goto exit_early;
 -                      else
 -                              dir_add_name(dir, path.buf, path.len);
 +      if (!fdir)
 +              return 0;
 +
-       memcpy(path, base, baselen);
++      strbuf_add(&path, base, baselen);
 +
 +      while ((de = readdir(fdir)) != NULL) {
-               int len;
-               switch (treat_path(dir, de, path, sizeof(path),
-                                  baselen, simplify, &len)) {
++              switch (treat_path(dir, de, &path, baselen, simplify)) {
 +              case path_recurse:
-                       contents += read_directory_recursive(dir, path, len, 0, simplify);
++                      contents += read_directory_recursive(dir, path.buf,
++                                                           path.len, 0,
++                                                           simplify);
 +                      continue;
 +              case path_ignored:
 +                      continue;
 +              case path_handled:
 +                      break;
                }
 -exit_early:
 -              closedir(fdir);
 -              strbuf_release(&path);
 +              contents++;
 +              if (check_only)
 +                      goto exit_early;
 +              else
-                       dir_add_name(dir, path, len);
++                      dir_add_name(dir, path.buf, path.len);
        }
 +exit_early:
 +      closedir(fdir);
++      strbuf_release(&path);
  
        return contents;
  }