Re: [PATCH] dir: fix negative pathspecs in 'git ls-files' and 'git add'
- From
- Diogo Castro <diogo.filipe.acastro@gmail.com>
- Date
- Aug 31, 2026, 14:30 UTC
- Message-ID
- <CAJw8QBMmv=zLN6sd_W9uQMF3H6Baatyq=TogLyZSFXK2gN4V8w@mail.gmail.com>
- In-Reply-To
- <a8955129fcb7478f9739c8586c6975e1@CWXP265MB5784.GBRP265.PROD.OUTLOOK.COM>
I think there's some misunderstanding, please allow me to take a step back and attempt to clarify. My previous message was a reply to this:
> I am wondering if the solution is to compute common prefix across both positive and negative ones instead.
As far as I can tell, this "common prefix" feature does not affect the semantics of "ls-files" or "add", it doesn't affect which files are reported. It only affects the performance.
Your first example of "git ls-files -- a/b/c a/b/d :!a/b/" already works correctly, the pattern ":!a/b/" excludes everything from the first 2 pathspecs.
So the discussion to be had is purely about performance. My point was that computing the common prefix across both positive *and* negative pathspecs would not improve performance, and might actually make it worse.
The "common prefix" is mainly used to avoid walking the entire working directory. A couple of examples to illustrate:
* "git add -- a/b/c a/b/d ':!a/b/x'"
* Under the current implementation, the common prefix is "a/b/",
so as a performance optimization, we can look only into the "a/b/"
directory and ignore the others.
* Under your proposal of computing the "common prefix across both
positive and negative ones", the common prefix would still be "a/b/",
so performance wouldn't be affected.
* "git add -- a/b/c a/b/d ':!a/**/x'"
* Under the current implementation, the common prefix is "a/b/",
like in the example above.
* Under your proposal, the common prefix would be "a/", so we'd
have to walk _more_ directories, which would hurt performance.Does that answer your question? Or perhaps I misunderstood your point?