Skip to content

Commit 2974920

Browse files
committed
sparse-index: silently return when cache tree fails
If cache_tree_update() returns a non-zero value, then it could not create the cache tree. This is likely due to a path having a merge conflict. Since we are already returning early, let's return silently to avoid making it seem like we failed to write the index at all. If we remove our dependence on the cache tree within convert_to_sparse(), then we could still recover from this scenario and have a sparse index. When constructing the cache-tree extension in convert_to_sparse(), it is possible that we construct a tree object that is new to the object database. Without the WRITE_TREE_MISSING_OK flag, this results in an error that halts our conversion to a sparse index. Add this flag to remove this limitation. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 9dad0d2 commit 2974920

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sparse-index.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,15 @@ int convert_to_sparse(struct index_state *istate)
179179

180180
/* Clear and recompute the cache-tree */
181181
cache_tree_free(&istate->cache_tree);
182-
if (cache_tree_update(istate, 0)) {
183-
warning(_("unable to update cache-tree, staying full"));
184-
return -1;
185-
}
182+
/*
183+
* Silently return if there is a problem with the cache tree update,
184+
* which might just be due to a conflict state in some entry.
185+
*
186+
* This might create new tree objects, so be sure to use
187+
* WRITE_TREE_MISSING_OK.
188+
*/
189+
if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
190+
return 0;
186191

187192
remove_fsmonitor(istate);
188193

0 commit comments

Comments
 (0)