[PATCH v3 0/3] dir: fix pathspec prefixes with exclusions
- From
Yannik Tausch <dev@ytausch.de>
- Date
- Sep 3, 2026, 18:43 UTC
- Message-ID
- <887D6D84-F76E-4DCB-9633-CD78DA02BCC5@ytausch.de>
- In-Reply-To
- <886A25E6-8854-4AF6-BF0B-CFB57B673026@ytausch.de>
Pathspec prefix optimization must account for exclude items separately. The prefix is derived from non-exclude items, so applying it while matching an exclude item can compare the wrong portions of the paths. Conversely, an exclude item at the start of the pathspec currently prevents finding a common prefix among the remaining items.
The first patch, authored by Junio, marks the immutable strings in a pathspec item as const. The second patch matches exclude items against the full pathname. The third patch finds the common prefix starting with the first non-exclude item and returns both the prefix length and the string from which it was derived.
Changes since v2:
* Add Junio's preparatory const-correctness patch, which also fixes the unit test build with DEVELOPER=1. * Keep the two pathspec prefix fixes unchanged.
Junio C Hamano (1): pathspec: match and original in pathspec_item are const
Yannik Tausch (2): dir: do not apply prefix to negative pathspecs dir: find common prefix among non-exclude pathspec items
dir.c | 39 +++++++++++++++++++++---------------- pathspec.c | 4 ++-- pathspec.h | 4 ++-- t/t6132-pathspec-exclude.sh | 9 +++++++++ t/unit-tests/u-dir.c | 28 ++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 21 deletions(-)
Range-diff against v2: -: ---------- > 1: a257ce081e pathspec: match and original in pathspec_item are const 1: c8a2f1e22e = 2: 16c6df5080 dir: do not apply prefix to negative pathspecs 2: d0e08fdb96 = 3: b05b77f399 dir: find common prefix among non-exclude pathspec items
-- 2.55.0