Skip to content

Commit 77855d7

Browse files
committed
config: mark as sparse-index compatible
`git config --blob :.lfsconfig` (and similar :path lookups) triggers ensure_full_index() in sparse checkouts, expanding the entire sparse index to a full index. On large repositories this takes seconds even though the command only needs to look up a single path. The root cause has two parts: 1. `git config` uses RUN_SETUP_GENTLY and never calls repo_config(), so the sparse checkout globals (core.sparseCheckout, core.sparseCheckoutCone) are unset when the index is first read. 2. Without those globals, is_sparse_index_allowed() returns false, causing ensure_correct_sparsity() to call ensure_full_index() during do_read_index(). Fix this by loading repo config and setting command_requires_full_index to 0 in cmd_config(). This is the standard opt-in pattern used by the ~30 other commands that are sparse-index compatible. The repo_config() call is needed because RUN_SETUP_GENTLY does not load the default config callbacks that populate the sparse checkout globals. Other sparse-index-compatible commands use RUN_SETUP, which handles this during setup_git_directory(). The flag is safe to set unconditionally because git config only accesses the index when resolving --blob :path specs. For non-blob invocations, the flag has no effect. For --blob :path, in-cone paths resolve directly from the sparse index; out-of-cone paths trigger on-demand expansion through index_name_pos() with EXPAND_SPARSE. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
1 parent 1666c12 commit 77855d7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

builtin/config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,12 @@ int cmd_config(int argc,
16181618
*/
16191619
argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,
16201620
PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT);
1621+
if (startup_info->have_repository) {
1622+
repo_config(repo, git_default_config, NULL);
1623+
prepare_repo_settings(repo);
1624+
repo->settings.command_requires_full_index = 0;
1625+
}
1626+
16211627
if (subcommand) {
16221628
argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage,
16231629
PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT);

0 commit comments

Comments
 (0)