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
Diogo Castro <dc@diogocastro.com>
Date
Aug 30, 2026, 14:57 UTC
Message-ID
<CAJw8QBPbxangB90DceDXxaDmyz8fn5jbEUihhe2faJrZ3o7BeQ@mail.gmail.com>
In-Reply-To
<xmqqwlta2agt.fsf@gitster.g>
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.

On Sun, 30 Aug 2026 at 15:25, Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
>
> "Diogo Castro via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Diogo Castro <dc@diogocastro.com>
> >
> > `git ls-files` calls `common_prefix()` / `get_common_prefix_len()` which
> > calculate the length of the common prefix of all *positive* pathspecs,
> > `max_prefix_len`.
> > ...
> > Solution: in `do_match_pathspec()`, only strip the prefix when handling
> > positive pathspecs, not when handling negative pathspecs.
>
> Hmph, if the command line were
>
>         git ls-files -- a/b/c a/b/d !a/b/
>
> shouldn't we strip a/b/ from all three?  Would it make sense to
> leave the negative one relative to the full tree?  I am wondering
> if the solution is to compute common prefix across both positive and
> negative ones instead.
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.