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-07-14 16:12:25 +0300
committerJunio C Hamano <gitster@pobox.com>2021-07-14 23:42:21 +0300
commitfc6609d198c47bf511f3388975c7c94e0aa1af2b (patch)
tree3995ce3133182b4fe6315a10650157cbc6cd4b17 /sparse-index.c
parent670b81a890388c60b7032a4f5b879f2ece8c4558 (diff)
sparse-index: skip indexes with unmerged entries
The sparse-index format is designed to be compatible with merge conflicts, even those outside the sparse-checkout definition. The reason is that when converting a full index to a sparse one, a cache entry with nonzero stage will not be collapsed into a sparse directory entry. However, this behavior was not tested, and a different behavior within convert_to_sparse() fails in this scenario. Specifically, cache_tree_update() will fail when unmerged entries exist. convert_to_sparse_rec() uses the cache-tree data to recursively walk the tree structure, but also to compute the OIDs used in the sparse-directory entries. Add an index scan to convert_to_sparse() that will detect if these merge conflict entries exist and skip the conversion before trying to update the cache-tree. This is marked as NEEDSWORK because this can be removed with a suitable update to cache_tree_update() or a similar method that can construct a cache-tree with invalid nodes, but still allow creating the nodes necessary for creating sparse directory entries. It is possible that in the future we will not need to make such an update, since if we do not expand a sparse-index into a full one, this conversion does not need to happen. Thus, this can be deferred until the merge machinery is made to integrate with the sparse-index. Reviewed-by: Elijah Newren <newren@gmail.com> 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.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/sparse-index.c b/sparse-index.c
index affc4048f2..2c69593027 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -116,6 +116,17 @@ int set_sparse_index_config(struct repository *repo, int enable)
return res;
}
+static int index_has_unmerged_entries(struct index_state *istate)
+{
+ int i;
+ for (i = 0; i < istate->cache_nr; i++) {
+ if (ce_stage(istate->cache[i]))
+ return 1;
+ }
+
+ return 0;
+}
+
int convert_to_sparse(struct index_state *istate)
{
int test_env;
@@ -152,6 +163,13 @@ int convert_to_sparse(struct index_state *istate)
return -1;
}
+ /*
+ * NEEDSWORK: If we have unmerged entries, then stay full.
+ * Unmerged entries prevent the cache-tree extension from working.
+ */
+ if (index_has_unmerged_entries(istate))
+ return 0;
+
if (cache_tree_update(istate, 0)) {
warning(_("unable to update cache-tree, staying full"));
return -1;