]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-index: recompute cache-tree
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 29 Jun 2021 02:13:05 +0000 (02:13 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Jul 2021 22:05:53 +0000 (15:05 -0700)
When some commands run with command_requires_full_index=1, then the
index can get in a state where the in-memory cache tree is actually
equal to the sparse index's cache tree instead of the full one.

This results in incorrect entry_count values. By clearing the cache
tree before converting to sparse, we avoid this issue.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sparse-index.c

index 53c8f711ccc82e231b4e55a6de217798ce2fefc0..c6b4feec413a8ffeda31cadee1a85020abca466b 100644 (file)
@@ -170,6 +170,8 @@ int convert_to_sparse(struct index_state *istate)
        if (index_has_unmerged_entries(istate))
                return 0;
 
+       /* Clear and recompute the cache-tree */
+       cache_tree_free(&istate->cache_tree);
        if (cache_tree_update(istate, 0)) {
                warning(_("unable to update cache-tree, staying full"));
                return -1;