Skip to content

Commit 2de37c5

Browse files
derrickstoleegitster
authored andcommitted
cache-tree: integrate with sparse directory entries
The cache-tree extension was previously disabled with sparse indexes. However, the cache-tree is an important performance feature for commands like 'git status' and 'git add'. Integrate it with sparse directory entries. When writing a sparse index, completely clear and recalculate the cache tree. By starting from scratch, the only integration necessary is to check if we hit a sparse directory entry and create a leaf of the cache-tree that has an entry_count of one and no subtrees. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcc5fd5 commit 2de37c5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

cache-tree.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ static int update_one(struct cache_tree *it,
256256

257257
*skip_count = 0;
258258

259+
/*
260+
* If the first entry of this region is a sparse directory
261+
* entry corresponding exactly to 'base', then this cache_tree
262+
* struct is a "leaf" in the data structure, pointing to the
263+
* tree OID specified in the entry.
264+
*/
265+
if (entries > 0) {
266+
const struct cache_entry *ce = cache[0];
267+
268+
if (S_ISSPARSEDIR(ce->ce_mode) &&
269+
ce->ce_namelen == baselen &&
270+
!strncmp(ce->name, base, baselen)) {
271+
it->entry_count = 1;
272+
oidcpy(&it->oid, &ce->oid);
273+
return 1;
274+
}
275+
}
276+
259277
if (0 <= it->entry_count && has_object_file(&it->oid))
260278
return it->entry_count;
261279

sparse-index.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ int convert_to_sparse(struct index_state *istate)
172172
istate->cache_nr = convert_to_sparse_rec(istate,
173173
0, 0, istate->cache_nr,
174174
"", 0, istate->cache_tree);
175-
istate->drop_cache_tree = 1;
175+
176+
/* Clear and recompute the cache-tree */
177+
cache_tree_free(&istate->cache_tree);
178+
cache_tree_update(istate, 0);
179+
176180
istate->sparse_index = 1;
177181
trace2_region_leave("index", "convert_to_sparse", istate->repo);
178182
return 0;
@@ -273,5 +277,9 @@ void ensure_full_index(struct index_state *istate)
273277
strbuf_release(&base);
274278
free(full);
275279

280+
/* Clear and recompute the cache-tree */
281+
cache_tree_free(&istate->cache_tree);
282+
cache_tree_update(istate, 0);
283+
276284
trace2_region_leave("index", "ensure_full_index", istate->repo);
277285
}

0 commit comments

Comments
 (0)