sparse-index: enforce declaration and convert mv#2145
Draft
spkrka wants to merge 2 commits into
Draft
Conversation
|
There is an issue in commit 2268475:
|
|
There is an issue in commit a078fa9:
|
1092827 to
d56770f
Compare
3c31623 (sparse-index: add guard to ensure full index, 2021-01-08) introduced command_requires_full_index as scaffolding: every command starts by expanding the sparse index, and commands opt out one by one by setting the field to 0. Because the default is 1, a command that never touches the field silently gets full expansion -- there is no signal that it was forgotten rather than intentionally left. Change the default to a sentinel (-1) and add an accessor that dies if a command reaches index reading without declaring a value. An environment variable GIT_ALLOW_SPARSE_INDEX_WITHOUT_DECLARATION=1 bypasses the check as a safety net. Both the safety net and the field itself are meant to be removed once no commands require full expansion from the start. Four commands that never declared this field are surfaced and explicitly set to 1 to preserve existing behavior: - git-am - git-mv - git-submodule--helper - grep's submodule path Behavior change: any undeclared code path will now die() instead of silently expanding. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
In-cone moves already work without expanding the index, since index_name_pos() auto-expands sparse directory entries on demand. For out-of-cone moves (--sparse), call ensure_full_index() up front because the bulk iteration assumes individual file entries. Without --sparse, moving a sparse directory should produce the helpful "Use the --sparse option" hint. The old code relied on full index expansion to make the individual skip-worktree entries visible to the error path. Now that the index stays sparse, teach empty_dir_has_sparse_contents() to recognize sparse directory entries directly and short-circuit to the hint. As a side effect the error now names the directory the user typed rather than listing each file inside it. Add tests verifying that in-cone renames do not expand the index, that out-of-cone moves without --sparse produce the hint, and that --sparse triggers expansion. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
d56770f to
04e22e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
command_requires_full_indexwas introduced as scaffolding for thesparse-index work in 2021 by Stolee (3c31623). The idea was to
start with every command expanding the sparse index, then convert
them one by one until the field could be removed entirely.
Over the following years, ~30 commands were converted (most recently
merge-ours in Feb 2026 and apply in May 2025). Because the field
defaults to 1 in prepare_repo_settings(), any command that never
sets it silently gets full expansion -- it is easy to spot commands
that explicitly set it to 0, but hard to notice the ones that never
declared anything at all.
Only four commands still require full expansion: git-am, git-mv,
git-submodule--helper, and grep's submodule path.
This series does two things:
Makes it explicit which commands remain -- every command must now
declare the value as 0 or 1, or the accessor dies.
Converts git-mv, which seemed like the most useful one for sparse
checkouts in practice.
I also added a small safety net that I am not sure was a good idea.
I did not find any remaining undeclared path, but just in case there
is an environment variable (GIT_ALLOW_SPARSE_INDEX_WITHOUT_DECLARATION)
that users can set to bypass the check.