Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit ebb3289

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 429bb40 commit ebb3289

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

builtin/add.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
208208
i = dir->nr;
209209
while (--i >= 0) {
210210
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))
213212
*dst++ = entry;
214213
else if (flag & WARN_IMPLICIT_DOT)
215214
/*

builtin/grep.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
524524

525525
fill_directory(&dir, pathspec);
526526
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))
530528
continue;
531529
hit |= grep_file(opt, dir.entries[i]->name);
532530
if (hit && opt->status_only)

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
6464
if (len >= ent->len)
6565
die("git ls-files: internal error - directory entry not superset of prefix");
6666

67-
if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
67+
if (!dir_path_match(ent, &pathspec, len, ps_matched))
6868
return;
6969

7070
fputs(tag, stdout);

dir.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,11 @@ static inline int ce_path_match(const struct cache_entry *ce,
212212
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
213213
}
214214

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+
215222
#endif

wt-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,15 @@ static void wt_status_collect_untracked(struct wt_status *s)
552552
for (i = 0; i < dir.nr; i++) {
553553
struct dir_entry *ent = dir.entries[i];
554554
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))
556556
string_list_insert(&s->untracked, ent->name);
557557
free(ent);
558558
}
559559

560560
for (i = 0; i < dir.ignored_nr; i++) {
561561
struct dir_entry *ent = dir.ignored[i];
562562
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))
564564
string_list_insert(&s->ignored, ent->name);
565565
free(ent);
566566
}

0 commit comments

Comments
 (0)