On Sat, Apr 12, 2025 at 11:57 AM Jeff King <peff@xxxxxxxx> wrote: > > On Sat, Apr 12, 2025 at 08:30:00AM +0530, JAYATHEERTH K wrote: > > > Upon a much closer look into the Git source code, specifically > > init_pathspec_item within pathspec.c, my previous hypothesis regarding > > the optimization check in do_match_pathspec appears to be incorrect, > > or at least not the root cause. > > I think you're still on the right track, but are just mis-interpreting > the item->magic field. It's about user-specified "magic" flags, one of > which is "treat this pathspec like a glob, even if the default (or an > earlier "literal" magic flag) would tell you not to do so". > Ok that makes a lot of sense I was actually tweaking around with has_wildcard but was confused with the chronology in cmd_add > I don't think there is a bit flag in the pathspec item for "this item > has glob meta characters". But we compute and record the offset of the > first such character in the "nowildcard_len" field (which is for most > cases much better, since we can optimize prefix matches for stuff like > "foo/bar/*"). > > And you can compare that to "len" to see if it does any globbing at all > (which should also naturally handle stuff like ":(literal)" because we > then mark the whole thing as "nowildcard"). > Understood!! makes sense again. > So something like this probably works: > > diff --git a/dir.c b/dir.c > index cbd82be6c9..85cc08f4fc 100644 > --- a/dir.c > +++ b/dir.c > @@ -519,7 +519,8 @@ static int do_match_pathspec(struct index_state *istate, > ( exclude && !(ps->items[i].magic & PATHSPEC_EXCLUDE))) > continue; > > - if (seen && seen[i] == MATCHED_EXACTLY) > + if (seen && seen[i] == MATCHED_EXACTLY && > + ps->items[i].nowildcard_len == ps->items[i].len) > continue; > /* > * Make exclude patterns optional and never report > > I think if you grep around for 'nowildcard_len ==' you'll find one or > two similar spots. > I did and found this (nowildcard_len) in attr files after tracing it up! Will send a patch in a new thread as soon as possible. > -Peff Thank you, Jayatheerth