diff options
Diffstat (limited to 'sparse-index.c')
-rw-r--r-- | sparse-index.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/sparse-index.c b/sparse-index.c index 6f4d95d35b..4c73772c6d 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -102,21 +102,32 @@ static int convert_to_sparse_rec(struct index_state *istate, return num_converted - start_converted; } -static int enable_sparse_index(struct repository *repo) +static int set_index_sparse_config(struct repository *repo, int enable) { - const char *config_path = repo_git_path(repo, "config.worktree"); - - git_config_set_in_file_gently(config_path, - "index.sparse", - "true"); + int res; + char *config_path = repo_git_path(repo, "config.worktree"); + res = git_config_set_in_file_gently(config_path, + "index.sparse", + enable ? "true" : NULL); + free(config_path); prepare_repo_settings(repo); repo->settings.sparse_index = 1; - return 0; + return res; +} + +int set_sparse_index_config(struct repository *repo, int enable) +{ + int res = set_index_sparse_config(repo, enable); + + prepare_repo_settings(repo); + repo->settings.sparse_index = enable; + return res; } int convert_to_sparse(struct index_state *istate) { + int test_env; if (istate->split_index || istate->sparse_index || !core_apply_sparse_checkout || !core_sparse_checkout_cone) return 0; @@ -128,11 +139,9 @@ int convert_to_sparse(struct index_state *istate) * The GIT_TEST_SPARSE_INDEX environment variable triggers the * index.sparse config variable to be on. */ - if (git_env_bool("GIT_TEST_SPARSE_INDEX", 0)) { - int err = enable_sparse_index(istate->repo); - if (err < 0) - return err; - } + test_env = git_env_bool("GIT_TEST_SPARSE_INDEX", -1); + if (test_env >= 0) + set_sparse_index_config(istate->repo, test_env); /* * Only convert to sparse if index.sparse is set. |