summaryrefslogtreecommitdiff
path: root/sparse-index.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-03-30 13:10:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-03-30 19:57:47 (GMT)
commit58300f4743231724686d9ddf481aeefa4f90d2f7 (patch)
tree0a73a7f7312d021f7891107d27f2ac0161e62202 /sparse-index.c
parent0938e6ff552510d4e6e495f062a9fab3e932178a (diff)
downloadgit-58300f4743231724686d9ddf481aeefa4f90d2f7.zip
git-58300f4743231724686d9ddf481aeefa4f90d2f7.tar.gz
git-58300f4743231724686d9ddf481aeefa4f90d2f7.tar.bz2
sparse-index: add index.sparse config option
When enabled, this config option signals that index writes should attempt to use sparse-directory entries. 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.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/sparse-index.c b/sparse-index.c
index 7631f7b..6f4d95d 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -102,19 +102,43 @@ static int convert_to_sparse_rec(struct index_state *istate,
return num_converted - start_converted;
}
+static int enable_sparse_index(struct repository *repo)
+{
+ const char *config_path = repo_git_path(repo, "config.worktree");
+
+ git_config_set_in_file_gently(config_path,
+ "index.sparse",
+ "true");
+
+ prepare_repo_settings(repo);
+ repo->settings.sparse_index = 1;
+ return 0;
+}
+
int convert_to_sparse(struct index_state *istate)
{
if (istate->split_index || istate->sparse_index ||
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
return 0;
+ if (!istate->repo)
+ istate->repo = the_repository;
+
+ /*
+ * 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;
+ }
+
/*
- * For now, only create a sparse index with the
- * GIT_TEST_SPARSE_INDEX environment variable. We will relax
- * this once we have a proper way to opt-in (and later still,
- * opt-out).
+ * Only convert to sparse if index.sparse is set.
*/
- if (!git_env_bool("GIT_TEST_SPARSE_INDEX", 0))
+ prepare_repo_settings(istate->repo);
+ if (!istate->repo->settings.sparse_index)
return 0;
if (!istate->sparse_checkout_patterns) {