git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] stash: avoid sparse-index expansion for in-cone paths

From
tnyman@openai.com <tnyman@openai.com>
Date
Jul 20, 2026, 22:31 UTC
Message-ID
<20260720223118.62821-4-tnyman@openai.com>
From: Ted Nyman <tnyman@openai.com>

`git stash push -- <pathspec>` expands a sparse index before checking whether the pathspec matches a tracked path. A pathspec wholly inside the sparse-checkout cone cannot match part of a sparse-directory entry, so that expansion needlessly makes the command proportional to the full index size.

The first patch fixes the pathspec helper to use the parsed, prefixed path consistently. The existing code can read past the end of the unprefixed path for a wildcard passed to `git rm` or `git reset` from a subdirectory; AddressSanitizer reports a heap-buffer-overflow in that case.

The second patch uses the helper in `git stash push`, following the same approach as bcf96cfca6 ("rm: expand the index only when necessary", 2022-08-07). It adds compatibility coverage for the supported pathspec forms and a 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 was:

  before: 18.87s (2.93s user + 15.62s system), 4 expansions
  after:   0.06s (0.01s user +  0.02s system), 0 expansions
A full-index control was unchanged (1.62s before, 1.65s after).

The series is based on 48bbf81c29 ("The 5th batch", 2026-07-19), the current master. Focused sparse-index, stash, pathspec, rm, reset, SHA-256, and unit-test coverage passes. Clang, GCC, and sanitizer builds also pass.

Ted Nyman (2):
  pathspec: use match for sparse-index expansion checks
  stash: avoid sparse-index expansion for in-cone paths
 builtin/stash.c                          |  4 +-
 pathspec.c                               | 12 ++---
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 62 ++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 8 deletions(-)
base-commit: 48bbf81c29ca9a4479ec7850fe206518682cdb2f
Next: tnyman@openai.com
Message 1 of 6 in “stash: avoid sparse-index expansion for in-cone paths”
  1. 0/2 stash: avoid sparse-index expansion for in-cone pathstnyman@openai.com, Jul 20, 2026
  2. 1/2 pathspec: use match for sparse-index expansion checkstnyman@openai.com, Jul 20, 2026
  3. Taylor BlauJul 20, 2026
  4. 2/2 stash: avoid sparse-index expansion for in-cone pathstnyman@openai.com, Jul 20, 2026
  5. Taylor BlauJul 20, 2026
  6. Junio C HamanoJul 21, 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.