]> git.ipfire.org Git - thirdparty/git.git/commit
stash: avoid sparse-index expansion for in-cone paths
authorTed Nyman <tnyman@openai.com>
Mon, 20 Jul 2026 22:31:21 +0000 (15:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Jul 2026 17:33:25 +0000 (10:33 -0700)
commit1be6ebe264031dc2175fec50c36df25fafd25084
treed6a5e5d0f93057d51477d81151660d9a0ce15ddc
parentdd674df3267112248b0012ce614168055a416920
stash: avoid sparse-index expansion for in-cone paths

`git stash push -- <pathspec>` expands a sparse index before checking
whether the pathspec matches any tracked paths. This is unnecessary
when the pathspec is wholly inside the sparse-checkout cone and makes
a path-limited stash proportional to the size of the full index.

Use `pathspec_needs_expanded_index()` to expand only when a pathspec
can match part of a sparse-directory entry, as `git rm` and `git
reset` already do. Keep the full-index behavior for pathspecs that
need it.

Add compatibility coverage for literal, prefixed, wildcard, file,
multiple, staged, and missing pathspecs. Add the corresponding
path-limited stash case to p2000.

On a cone-mode repository with 349,525 tracked paths and 49 sparse
index entries, the best of three runs changed from 18.87s to 0.06s.
Trace2 reported four index expansions before this change and none
after it.

Signed-off-by: Ted Nyman <tnyman@openai.com>
Reviewed-by: Taylor Blau <ttaylorr@openai.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/stash.c
t/perf/p2000-sparse-operations.sh
t/t1092-sparse-checkout-compatibility.sh