Skip to content

Commit

Permalink
sparse-index: recompute cache-tree
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
derrickstolee authored and gitster committed Jul 14, 2021
1 parent daa1ace commit f934f1b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f934f1b

Please sign in to comment.