convert {read,fill}_directory to take struct pathspec

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 14, 2013 at 15:35 UTC 7327d3d1b70bfde70840aa8970fe70de6ef1be16
7 files changed +20 -12
builtin/add.c
+3 -1
@@ -507,6 +507,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
507
508 if (add_new_files) {
509 int baselen;
510 + struct pathspec empty_pathspec;
511
512 /* Set up the default git porcelain excludes */
513 memset(&dir, 0, sizeof(dir));
@@ -515,8 +516,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
516 setup_standard_excludes(&dir);
517 }
518
519 + memset(&empty_pathspec, 0, sizeof(empty_pathspec));
520 /* This picks up the paths that are not tracked */
519 - baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec.raw);
521 + baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
522 if (pathspec.nr)
523 seen = prune_directory(&dir, pathspec.raw, baselen,
524 implicit_dot ? WARN_IMPLICIT_DOT : 0);
builtin/clean.c
+1 -1
@@ -214,7 +214,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
214 PATHSPEC_PREFER_CWD,
215 prefix, argv);
216
217 - fill_directory(&dir, pathspec.raw);
217 + fill_directory(&dir, &pathspec);
218
219 for (i = 0; i < dir.nr; i++) {
220 struct dir_entry *ent = dir.entries[i];
builtin/grep.c
+1 -1
@@ -523,7 +523,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
523 if (exc_std)
524 setup_standard_excludes(&dir);
525
526 - fill_directory(&dir, pathspec->raw);
526 + fill_directory(&dir, pathspec);
527 for (i = 0; i < dir.nr; i++) {
528 const char *name = dir.entries[i]->name;
529 int namelen = strlen(name);
builtin/ls-files.c
+1 -1
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
216
217 /* For cached/deleted files we don't need to even do the readdir */
218 if (show_others || show_killed) {
219 - fill_directory(dir, pathspec.raw);
219 + fill_directory(dir, &pathspec);
220 if (show_others)
221 show_other_files(dir);
222 if (show_killed)
dir.c
+11 -5
@@ -142,7 +142,7 @@ char *common_prefix(const char **pathspec)
142 return len ? xmemdupz(*pathspec, len) : NULL;
143 }
144
145 -int fill_directory(struct dir_struct *dir, const char **pathspec)
145 +int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
146 {
147 size_t len;
148
@@ -150,10 +150,10 @@ int fill_directory(struct dir_struct *dir, const char **pathspec)
150 * Calculate common prefix for the pathspec, and
151 * use that to optimize the directory walk
152 */
153 - len = common_prefix_len(pathspec);
153 + len = common_prefix_len(pathspec->raw);
154
155 /* Read the directory and prune it */
156 - read_directory(dir, pathspec ? *pathspec : "", len, pathspec);
156 + read_directory(dir, pathspec->nr ? pathspec->raw[0] : "", len, pathspec);
157 return len;
158 }
159
@@ -1388,14 +1388,20 @@ static int treat_leading_path(struct dir_struct *dir,
1388 return rc;
1389 }
1390
1391 -int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec)
1391 +int read_directory(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec)
1392 {
1393 struct path_simplify *simplify;
1394
1395 + /*
1396 + * Check out create_simplify()
1397 + */
1398 + if (pathspec)
1399 + GUARD_PATHSPEC(pathspec, PATHSPEC_FROMTOP | PATHSPEC_MAXDEPTH);
1400 +
1401 if (has_symlink_leading_path(path, len))
1402 return dir->nr;
1403
1398 - simplify = create_simplify(pathspec);
1404 + simplify = create_simplify(pathspec ? pathspec->raw : NULL);
1405 if (!len || treat_leading_path(dir, path, len, simplify))
1406 read_directory_recursive(dir, path, len, 0, simplify);
1407 free_simplify(simplify);
dir.h
+2 -2
@@ -137,8 +137,8 @@ extern int match_pathspec_depth(const struct pathspec *pathspec,
137 int prefix, char *seen);
138 extern int within_depth(const char *name, int namelen, int depth, int max_depth);
139
140 -extern int fill_directory(struct dir_struct *dir, const char **pathspec);
141 -extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec);
140 +extern int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec);
141 +extern int read_directory(struct dir_struct *, const char *path, int len, const struct pathspec *pathspec);
142
143 extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
144 int *dtype, struct exclude_list *el);
wt-status.c
+1 -1
@@ -514,7 +514,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
514 dir.flags |= DIR_SHOW_IGNORED_TOO;
515 setup_standard_excludes(&dir);
516
517 - fill_directory(&dir, s->pathspec.raw);
517 + fill_directory(&dir, &s->pathspec);
518
519 for (i = 0; i < dir.nr; i++) {
520 struct dir_entry *ent = dir.entries[i];