Re: [PATCH 2/2] dir: do not feed path suffix to pathspec match
From: René Scharfe <hidden>
Date: 2023-07-08 07:16:26
Am 08.07.23 um 00:04 schrieb Junio C Hamano:
quoted hunk ↗ jump to hunk
diff --git a/dir.c b/dir.c index 3acac7beb1..6116022ae6 100644 --- a/dir.c +++ b/dir.c@@ -488,9 +476,6 @@ static int do_match_pathspec(struct index_state *istate, return 0; } - name += prefix; - namelen -= prefix; - for (i = ps->nr - 1; i >= 0; i--) { int how;@@ -506,8 +491,8 @@ static int do_match_pathspec(struct index_state *istate, */ if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE) seen[i] = MATCHED_FNMATCH; - how = match_pathspec_item(istate, ps->items+i, prefix, name, - namelen, flags); + how = match_pathspec_item(istate, ps->items+i, + name, namelen, flags);
With that, the parameter "prefix" of do_match_pathspec() becomes unused
and can be removed. This cascades to match_pathspec_with_flags(),
match_pathspec(), dir_path_match() and builtin/add.c::prune_directory(),
and fill_directory() can lose its return value.
The code continues here like this, though:
if (ps->recursive &&
(ps->magic & PATHSPEC_MAXDEPTH) &&
ps->max_depth != -1 &&
how && how != MATCHED_FNMATCH) {
int len = ps->items[i].len;
if (name[len] == '/')
len++;
if (within_depth(name+len, namelen-len, 0, ps->max_depth))
how = MATCHED_EXACTLY;
else
how = 0;
}
And "name" here would be affected by "prefix" no longer being added.
Does it fix or break --max-depth? I think neither: builtin/grep.c --
the only user of PATHSPEC_MAXDEPTH AFAICS -- passes a prefix of 0.
René