Skip to content

sparse-index: enforce declaration and convert mv#2145

Draft
spkrka wants to merge 2 commits into
gitgitgadget:masterfrom
spkrka:krka/sparse-index-strict
Draft

sparse-index: enforce declaration and convert mv#2145
spkrka wants to merge 2 commits into
gitgitgadget:masterfrom
spkrka:krka/sparse-index-strict

Conversation

@spkrka

@spkrka spkrka commented Jun 9, 2026

Copy link
Copy Markdown

command_requires_full_index was introduced as scaffolding for the
sparse-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:

  1. Makes it explicit which commands remain -- every command must now
    declare the value as 0 or 1, or the accessor dies.

  2. 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.

@gitgitgadget

gitgitgadget Bot commented Jun 9, 2026

Copy link
Copy Markdown

There is an issue in commit 2268475:
sparse-index: require commands to declare sparse-index compatibility

  • Commit not signed off

@gitgitgadget

gitgitgadget Bot commented Jun 9, 2026

Copy link
Copy Markdown

There is an issue in commit a078fa9:
sparse-index: mark mv as sparse-index compatible

  • Commit not signed off

@spkrka spkrka force-pushed the krka/sparse-index-strict branch 2 times, most recently from 1092827 to d56770f Compare June 9, 2026 18:45
spkrka added 2 commits June 9, 2026 21:12
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>
@spkrka spkrka force-pushed the krka/sparse-index-strict branch from d56770f to 04e22e2 Compare June 9, 2026 19:13
@spkrka spkrka changed the title sparse-index: enforce declaration and optimize mv sparse-index: enforce declaration and convert mv Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant