Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-09-08 04:42:32 +0300
committerJunio C Hamano <gitster@pobox.com>2021-09-08 08:41:10 +0300
commitce7a9f014167ccf137eb09d5546eb1e8b550f11b (patch)
tree7dac8662ce71ad191b0341adea253ac88852d257 /sparse-index.c
parent77efbb366abe53792511580b96a39c636c5b0401 (diff)
sparse-index: add SPARSE_INDEX_MEMORY_ONLY flag
The convert_to_sparse() method checks for the GIT_TEST_SPARSE_INDEX environment variable or the "index.sparse" config setting before converting the index to a sparse one. This is for ease of use since all current consumers are preparing to compress the index before writing it to disk. If these settings are not enabled, then convert_to_sparse() silently returns without doing anything. We will add a consumer in the next change that wants to use the sparse index as an in-memory data structure, regardless of whether the on-disk format should be sparse. To that end, create the SPARSE_INDEX_MEMORY_ONLY flag that will skip these config checks when enabled. All current consumers are modified to pass '0' in the new 'flags' parameter. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sparse-index.c')
-rw-r--r--sparse-index.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/sparse-index.c b/sparse-index.c
index 23f7c3bd36..0bc45f60ac 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -122,30 +122,37 @@ static int index_has_unmerged_entries(struct index_state *istate)
return 0;
}
-int convert_to_sparse(struct index_state *istate)
+int convert_to_sparse(struct index_state *istate, int flags)
{
int test_env;
- if (istate->split_index || istate->sparse_index || !istate->cache_nr ||
+ if (istate->sparse_index || !istate->cache_nr ||
!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.
- */
- test_env = git_env_bool("GIT_TEST_SPARSE_INDEX", -1);
- if (test_env >= 0)
- set_sparse_index_config(istate->repo, test_env);
+ if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {
+ /*
+ * The sparse index is not (yet) integrated with a split index.
+ */
+ if (istate->split_index)
+ return 0;
+ /*
+ * The GIT_TEST_SPARSE_INDEX environment variable triggers the
+ * index.sparse config variable to be on.
+ */
+ 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.
- */
- prepare_repo_settings(istate->repo);
- if (!istate->repo->settings.sparse_index)
- return 0;
+ /*
+ * Only convert to sparse if index.sparse is set.
+ */
+ prepare_repo_settings(istate->repo);
+ if (!istate->repo->settings.sparse_index)
+ return 0;
+ }
if (init_sparse_checkout_patterns(istate))
return 0;