sparse-checkout: toggle sparse index from builtin
The sparse index extension is used to signal that index writes should be in sparse mode. This was only updated using GIT_TEST_SPARSE_INDEX=1. Add a '--[no-]sparse-index' option to 'git sparse-checkout init' that specifies if the sparse index should be used. It also updates the index to use the correct format, either way. Add a warning in the documentation that the use of a repository extension might reduce compatibility with third-party tools. 'git sparse-checkout init' already sets extension.worktreeConfig, which places most sparse-checkout users outside of the scope of most third-party tools. Update t1092-sparse-checkout-compatibility.sh to use this CLI instead of GIT_TEST_SPARSE_INDEX=1. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
58300f4743
commit
122ba1f7b5
@ -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.
|
||||
|
Reference in New Issue
Block a user