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:
authorVictoria Dye <vdye@github.com>2021-11-23 03:20:31 +0300
committerJunio C Hamano <gitster@pobox.com>2021-11-25 03:32:38 +0300
commit13f69f30826001d6a98a36854d0c92a61d0dfcb8 (patch)
tree8821622932992b632d768690d196310475cc49a2 /sparse-index.c
parent336d82e47235fdfb093fefbd6b6595deaab6ca2b (diff)
sparse-index: avoid unnecessary cache tree clearing
When converting a full index to sparse, clear and recreate the cache tree only if the cache tree is not fully valid. The convert_to_sparse operation should exit silently if a cache tree update cannot be successfully completed (e.g., due to a conflicted entry state). However, because this failure scenario only occurs when at least a portion of the cache tree is invalid, we can save ourselves the cost of clearing and recreating the cache tree by skipping the check when the cache tree is fully valid. Helped-by: Derrick Stolee <dstolee@microsoft.com> Co-authored-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Victoria Dye <vdye@github.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.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sparse-index.c b/sparse-index.c
index 7b7ff79e04..85613cd8a3 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -175,17 +175,20 @@ int convert_to_sparse(struct index_state *istate, int flags)
if (index_has_unmerged_entries(istate))
return 0;
- /* Clear and recompute the cache-tree */
- cache_tree_free(&istate->cache_tree);
- /*
- * Silently return if there is a problem with the cache tree update,
- * which might just be due to a conflict state in some entry.
- *
- * This might create new tree objects, so be sure to use
- * WRITE_TREE_MISSING_OK.
- */
- if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
- return 0;
+ if (!cache_tree_fully_valid(istate->cache_tree)) {
+ /* Clear and recompute the cache-tree */
+ cache_tree_free(&istate->cache_tree);
+
+ /*
+ * Silently return if there is a problem with the cache tree update,
+ * which might just be due to a conflict state in some entry.
+ *
+ * This might create new tree objects, so be sure to use
+ * WRITE_TREE_MISSING_OK.
+ */
+ if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
+ return 0;
+ }
remove_fsmonitor(istate);