Skip to content

Commit e27eab4

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 522d3ce commit e27eab4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sparse-index.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int index_has_unmerged_entries(struct index_state *istate)
130130
int convert_to_sparse(struct index_state *istate)
131131
{
132132
int test_env;
133-
if (istate->split_index || istate->sparse_index ||
133+
if (istate->split_index || istate->sparse_index || !istate->cache_nr ||
134134
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
135135
return 0;
136136

@@ -158,10 +158,16 @@ int convert_to_sparse(struct index_state *istate)
158158
return 0;
159159
}
160160

161-
if (!istate->sparse_checkout_patterns->use_cone_patterns) {
162-
warning(_("attempting to use sparse-index without cone mode"));
163-
return -1;
164-
}
161+
/*
162+
* We need cone-mode patterns to use sparse-index. If a user edits
163+
* their sparse-checkout file manually, then we can detect during
164+
* parsing that they are not actually using cone-mode patterns and
165+
* hence we need to abort this conversion _without error_. Warnings
166+
* already exist in the pattern parsing to inform the user of their
167+
* bad patterns.
168+
*/
169+
if (!istate->sparse_checkout_patterns->use_cone_patterns)
170+
return 0;
165171

166172
/*
167173
* NEEDSWORK: If we have unmerged entries, then stay full.

0 commit comments

Comments
 (0)