]> git.ipfire.org Git - thirdparty/git.git/commit
ls-files: conditionally leave index sparse
authorDerrick Stolee <stolee@gmail.com>
Fri, 15 Aug 2025 16:12:53 +0000 (16:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Aug 2025 15:02:37 +0000 (08:02 -0700)
commit681f26bccc017371ae6ee20db55e3edb52420a25
tree3417455b18f47ef44a3061afe13a298f032b5995
parentf368df439b31b422169975cc3c95f7db6a46eada
ls-files: conditionally leave index sparse

When running 'git ls-files' with a pathspec, the index entries get
filtered according to that pathspec before iterating over them in
show_files().  In 78087097b8 (ls-files: add --sparse option,
2021-12-22), this iteration was prefixed with a check for the '--sparse'
option which allows the command to output directory entries; this
created a pre-loop call to ensure_full_index().

However, when a user runs 'git ls-files' where the pathspec matches
directories that are recursively matched in the sparse-checkout, there
are not any sparse directories that match the pathspec so they would not
be written to the output. The expansion in this case is just a
performance drop for no behavior difference.

Replace this global check to expand the index with a check inside the
loop for a matched sparse directory. If we see one, then expand the
index and continue from the current location. This is safe since the
previous entries in the index did not have any sparse directories and
thus would remain stable in this expansion.

A test in t1092 confirms that this changes the behavior.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-files.c
t/t1092-sparse-checkout-compatibility.sh