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 31, 2026, 18:26 UTC
Message-ID
<xmqqv78qw3hc.fsf@gitster.g>
In-Reply-To
<CAJw8QBMmv=zLN6sd_W9uQMF3H6Baatyq=TogLyZSFXK2gN4V8w@mail.gmail.com>
Diogo Castro <diogo.filipe.acastro@gmail.com> writes:
> My point was that computing the common prefix across both positive
> *and* negative pathspecs would not improve performance, and might
> actually make it worse.

OK. Then that points at the right solution. Ignore negative ones when finding what the common prefix is, strip it only from positive ones to reduce the width of the traversal to come up with the list of possible match candidates, and match them as full paths against the negative ones to cull "within the positive set but is excluded" paths, and the posted patch looks good.

I still wonder if we need different implementation when we have many more negative patterns than the positive ones. In such a case, the stage to filter paths that matched one positive pattern by finding matches with a negative pattern among many of them, which may benefit from having a similar common prefix (among negative patterns) optimization, but that is a separate topic.

Thanks.
Previous: Diogo CastroNext: Diogo Castro
Message 6 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.