pathspec: convert some match_pathspec_depth() to dir_path_match()
This helps reduce the number of match_pathspec_depth() call sites and show how m_p_d() is used. And it usage is: - match against an index entry (ce_path_match or match_pathspec_depth in ls-files) - match against a dir_entry from read_directory (dir_path_match and match_pathspec_depth in clean.c, which will be converted later) - resolve-undo (rerere.c and ls-files.c) 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
Jan 24, 2014 at 20:40 UTC
ebb32893bad46bf5edae881552672a47dd2684b8
5 files changed
+12
-8
builtin/add.c
+1
-2
@@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
208
i = dir->nr;
209
while (--i >= 0) {
210
struct dir_entry *entry = *src++;
211
- if (match_pathspec_depth(pathspec, entry->name, entry->len,
212
- prefix, seen))
211
+ if (dir_path_match(entry, pathspec, prefix, seen))
212
*dst++ = entry;
213
else if (flag & WARN_IMPLICIT_DOT)
214
/*
builtin/grep.c
+1
-3
@@ -524,9 +524,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
524
525
fill_directory(&dir, pathspec);
526
for (i = 0; i < dir.nr; i++) {
527
- const char *name = dir.entries[i]->name;
528
- int namelen = strlen(name);
529
- if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
527
+ if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
528
continue;
529
hit |= grep_file(opt, dir.entries[i]->name);
530
if (hit && opt->status_only)
builtin/ls-files.c
+1
-1
@@ -64,7 +64,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
64
if (len >= ent->len)
65
die("git ls-files: internal error - directory entry not superset of prefix");
66
67
- if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
67
+ if (!dir_path_match(ent, &pathspec, len, ps_matched))
68
return;
69
70
fputs(tag, stdout);
dir.h
+7
@@ -212,4 +212,11 @@ static inline int ce_path_match(const struct cache_entry *ce,
212
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
213
}
214
215
+static inline int dir_path_match(const struct dir_entry *ent,
216
+ const struct pathspec *pathspec,
217
+ int prefix, char *seen)
218
+{
219
+ return match_pathspec_depth(pathspec, ent->name, ent->len, prefix, seen);
220
+}
221
+
222
#endif
wt-status.c
+2
-2
@@ -552,7 +552,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
552
for (i = 0; i < dir.nr; i++) {
553
struct dir_entry *ent = dir.entries[i];
554
if (cache_name_is_other(ent->name, ent->len) &&
555
- match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
555
+ dir_path_match(ent, &s->pathspec, 0, NULL))
556
string_list_insert(&s->untracked, ent->name);
557
free(ent);
558
}
@@ -560,7 +560,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
560
for (i = 0; i < dir.ignored_nr; i++) {
561
struct dir_entry *ent = dir.ignored[i];
562
if (cache_name_is_other(ent->name, ent->len) &&
563
- match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
563
+ dir_path_match(ent, &s->pathspec, 0, NULL))
564
string_list_insert(&s->ignored, ent->name);
565
free(ent);
566
}