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>maint
parent
429bb40abd
commit
ebb32893ba
|
@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
|
||||||
i = dir->nr;
|
i = dir->nr;
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
struct dir_entry *entry = *src++;
|
struct dir_entry *entry = *src++;
|
||||||
if (match_pathspec_depth(pathspec, entry->name, entry->len,
|
if (dir_path_match(entry, pathspec, prefix, seen))
|
||||||
prefix, seen))
|
|
||||||
*dst++ = entry;
|
*dst++ = entry;
|
||||||
else if (flag & WARN_IMPLICIT_DOT)
|
else if (flag & WARN_IMPLICIT_DOT)
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -524,9 +524,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
|
|
||||||
fill_directory(&dir, pathspec);
|
fill_directory(&dir, pathspec);
|
||||||
for (i = 0; i < dir.nr; i++) {
|
for (i = 0; i < dir.nr; i++) {
|
||||||
const char *name = dir.entries[i]->name;
|
if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
|
||||||
int namelen = strlen(name);
|
|
||||||
if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
|
|
||||||
continue;
|
continue;
|
||||||
hit |= grep_file(opt, dir.entries[i]->name);
|
hit |= grep_file(opt, dir.entries[i]->name);
|
||||||
if (hit && opt->status_only)
|
if (hit && opt->status_only)
|
||||||
|
|
|
@ -64,7 +64,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
|
||||||
if (len >= ent->len)
|
if (len >= ent->len)
|
||||||
die("git ls-files: internal error - directory entry not superset of prefix");
|
die("git ls-files: internal error - directory entry not superset of prefix");
|
||||||
|
|
||||||
if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
|
if (!dir_path_match(ent, &pathspec, len, ps_matched))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fputs(tag, stdout);
|
fputs(tag, stdout);
|
||||||
|
|
7
dir.h
7
dir.h
|
@ -212,4 +212,11 @@ static inline int ce_path_match(const struct cache_entry *ce,
|
||||||
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
|
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int dir_path_match(const struct dir_entry *ent,
|
||||||
|
const struct pathspec *pathspec,
|
||||||
|
int prefix, char *seen)
|
||||||
|
{
|
||||||
|
return match_pathspec_depth(pathspec, ent->name, ent->len, prefix, seen);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -552,7 +552,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
|
||||||
for (i = 0; i < dir.nr; i++) {
|
for (i = 0; i < dir.nr; i++) {
|
||||||
struct dir_entry *ent = dir.entries[i];
|
struct dir_entry *ent = dir.entries[i];
|
||||||
if (cache_name_is_other(ent->name, ent->len) &&
|
if (cache_name_is_other(ent->name, ent->len) &&
|
||||||
match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
|
dir_path_match(ent, &s->pathspec, 0, NULL))
|
||||||
string_list_insert(&s->untracked, ent->name);
|
string_list_insert(&s->untracked, ent->name);
|
||||||
free(ent);
|
free(ent);
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
|
||||||
for (i = 0; i < dir.ignored_nr; i++) {
|
for (i = 0; i < dir.ignored_nr; i++) {
|
||||||
struct dir_entry *ent = dir.ignored[i];
|
struct dir_entry *ent = dir.ignored[i];
|
||||||
if (cache_name_is_other(ent->name, ent->len) &&
|
if (cache_name_is_other(ent->name, ent->len) &&
|
||||||
match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
|
dir_path_match(ent, &s->pathspec, 0, NULL))
|
||||||
string_list_insert(&s->ignored, ent->name);
|
string_list_insert(&s->ignored, ent->name);
|
||||||
free(ent);
|
free(ent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue