summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2021-03-30 13:11:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-03-30 19:57:48 (GMT)
commit2de37c536d54a28a032491ad4ef97632ef6ab836 (patch)
treee9eb29e598eb4cbb34ac3609ad9fe1189642fb61 /cache-tree.c
parentdcc5fd5fd26b71d75f9e70abd0e09e553b5f40ca (diff)
downloadgit-2de37c536d54a28a032491ad4ef97632ef6ab836.zip
git-2de37c536d54a28a032491ad4ef97632ef6ab836.tar.gz
git-2de37c536d54a28a032491ad4ef97632ef6ab836.tar.bz2
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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 5f07a39..950a961 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -256,6 +256,24 @@ static int update_one(struct cache_tree *it,
*skip_count = 0;
+ /*
+ * If the first entry of this region is a sparse directory
+ * entry corresponding exactly to 'base', then this cache_tree
+ * struct is a "leaf" in the data structure, pointing to the
+ * tree OID specified in the entry.
+ */
+ if (entries > 0) {
+ const struct cache_entry *ce = cache[0];
+
+ if (S_ISSPARSEDIR(ce->ce_mode) &&
+ ce->ce_namelen == baselen &&
+ !strncmp(ce->name, base, baselen)) {
+ it->entry_count = 1;
+ oidcpy(&it->oid, &ce->oid);
+ return 1;
+ }
+ }
+
if (0 <= it->entry_count && has_object_file(&it->oid))
return it->entry_count;