summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2016-07-16 07:06:27 +0200
committerJunio C Hamano <gitster@pobox.com>2016-07-18 13:45:33 -0700
commit6d6a782fbf83927212f348f91823d886c5cd6d85 (patch)
treef78051522c92b67cd414291fb6436c3d7893c676 /cache-tree.c
parentc041d54a741e516b5a743f4d27532e484f2a05d3 (diff)
downloadgit-6d6a782fbf83927212f348f91823d886c5cd6d85.tar.gz
cache-tree: do not generate empty trees as a result of all i-t-a subentriesnd/cache-tree-ita
If a subdirectory contains nothing but i-t-a entries, we generate an empty tree object and add it to its parent tree. Which is wrong. Such a subdirectory should not be added. Note that this has a cascading effect. If subdir 'a/b/c' contains nothing but i-t-a entries, we ignore it. But then if 'a/b' contains only (the non-existing) 'a/b/c', then we should ignore 'a/b' while building 'a' too. And it goes all the way up to top directory. Noticed-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/cache-tree.c b/cache-tree.c
index c2676e8a31..f28b1f45a4 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -325,6 +325,7 @@ static int update_one(struct cache_tree *it,
const unsigned char *sha1;
unsigned mode;
int expected_missing = 0;
+ int contains_ita = 0;
path = ce->name;
pathlen = ce_namelen(ce);
@@ -341,7 +342,8 @@ static int update_one(struct cache_tree *it,
i += sub->count;
sha1 = sub->cache_tree->sha1;
mode = S_IFDIR;
- if (sub->cache_tree->entry_count < 0) {
+ contains_ita = sub->cache_tree->entry_count < 0;
+ if (contains_ita) {
to_invalidate = 1;
expected_missing = 1;
}
@@ -380,6 +382,12 @@ static int update_one(struct cache_tree *it,
continue;
}
+ /*
+ * "sub" can be an empty tree if all subentries are i-t-a.
+ */
+ if (contains_ita && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN))
+ continue;
+
strbuf_grow(&buffer, entlen + 100);
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
strbuf_add(&buffer, sha1, 20);