git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] dir: fix negative pathspecs in 'git ls-files' and 'git add'

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 30, 2026, 22:58 UTC
Message-ID
<xmqqmru3z051.fsf@gitster.g>
In-Reply-To
<CAJw8QBPbxangB90DceDXxaDmyz8fn5jbEUihhe2faJrZ3o7BeQ@mail.gmail.com>
Diogo Castro <dc@diogocastro.com> writes:
Show 13 quoted lines
> I don't think so.
>
> As far as I can tell, the "strip the common prefix" feature is a
> performance optimization aimed at avoiding walking the working
> directory needlessly.
> So for `git add -- a/b/c a/b/d`, there's no need to look anywhere
> other than in `a/b/`.
>
> But extending the "strip the common prefix" to negative pathspecs
> could end up negating the benefits we get from this perf optimization.
> E.g. in `git add -- a/b/c a/b/d ':!*.md'`, there is no prefix common
> to *all* pathspecs, so we'd revert to walking the entire working
> directory, even though `a/b/` would still suffice.
I was wondering more about case like this:
    $ git add -- a/b/c a/b/d ':!a/b/x

I agree that it is nonsense to compute the common prefix over only positive ones, and then to strip the common prefix from both positive and negative ones, and it needs to be corrected.

Previous: Diogo CastroNext: Diogo Castro
Message 4 of 7 in “dir: fix negative pathspecs in 'git ls-files' and 'git add'”
  1. dir: fix negative pathspecs in 'git ls-files' and 'git add'Diogo Castro via GitGitGadget, Aug 28, 2026
  2. Junio C HamanoAug 28, 2026
  3. Diogo CastroAug 30, 2026
  4. Junio C HamanoAug 30, 2026
  5. Diogo CastroAug 31, 2026
  6. Junio C HamanoAug 31, 2026
  7. Diogo CastroOct 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.