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.