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:26 +0300
committerJunio C Hamano <gitster@pobox.com>2021-09-08 08:41:09 +0300
commite27eab45c758bf194157b819fae4fd0fcce498fb (patch)
tree607945e29c7a1c69d288b8487fee8ad277dae175 /sparse-index.c
parent522d3cec0089228d0b1a5178c396662953cb2dc2 (diff)
sparse-index: silently return when not using cone-mode patterns
While the sparse-index is only enabled when core.sparseCheckoutCone is also enabled, it is possible for the user to modify the sparse-checkout file manually in a way that does not match cone-mode patterns. In this case, we should refuse to convert an index into a sparse index, since the sparse_checkout_patterns will not be initialized with recursive and parent path hashsets. Also silently return if there are no cache entries, which is a simple case: there are no paths to make sparse! 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.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/sparse-index.c b/sparse-index.c
index c6b4feec41..cd6e0d5f40 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -130,7 +130,7 @@ static int index_has_unmerged_entries(struct index_state *istate)
int convert_to_sparse(struct index_state *istate)
{
int test_env;
- if (istate->split_index || istate->sparse_index ||
+ if (istate->split_index || istate->sparse_index || !istate->cache_nr ||
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
return 0;
@@ -158,10 +158,16 @@ int convert_to_sparse(struct index_state *istate)
return 0;
}
- if (!istate->sparse_checkout_patterns->use_cone_patterns) {
- warning(_("attempting to use sparse-index without cone mode"));
- return -1;
- }
+ /*
+ * We need cone-mode patterns to use sparse-index. If a user edits
+ * their sparse-checkout file manually, then we can detect during
+ * parsing that they are not actually using cone-mode patterns and
+ * hence we need to abort this conversion _without error_. Warnings
+ * already exist in the pattern parsing to inform the user of their
+ * bad patterns.
+ */
+ if (!istate->sparse_checkout_patterns->use_cone_patterns)
+ return 0;
/*
* NEEDSWORK: If we have unmerged entries, then stay full.