summaryrefslogtreecommitdiff
path: root/sparse-index.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-03-30 13:11:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-03-30 19:57:48 (GMT)
commit122ba1f7b52612e197db76aded1f9681b80f3085 (patch)
tree96c6481a4c55e07f93667a601b475a6e759c4195 /sparse-index.c
parent58300f4743231724686d9ddf481aeefa4f90d2f7 (diff)
downloadgit-122ba1f7b52612e197db76aded1f9681b80f3085.zip
git-122ba1f7b52612e197db76aded1f9681b80f3085.tar.gz
git-122ba1f7b52612e197db76aded1f9681b80f3085.tar.bz2
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>
Diffstat (limited to 'sparse-index.c')
-rw-r--r--sparse-index.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/sparse-index.c b/sparse-index.c
index 6f4d95d..4c73772 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.