mirror of
https://github.com/git/git
synced 2024-07-05 00:58:49 +00:00
cache-tree: do not generate empty trees as a result of all i-t-a subentries
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>
This commit is contained in:
parent
c041d54a74
commit
6d6a782fbf
10
cache-tree.c
10
cache-tree.c
|
@ -325,6 +325,7 @@ static int update_one(struct cache_tree *it,
|
||||||
const unsigned char *sha1;
|
const unsigned char *sha1;
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
int expected_missing = 0;
|
int expected_missing = 0;
|
||||||
|
int contains_ita = 0;
|
||||||
|
|
||||||
path = ce->name;
|
path = ce->name;
|
||||||
pathlen = ce_namelen(ce);
|
pathlen = ce_namelen(ce);
|
||||||
|
@ -341,7 +342,8 @@ static int update_one(struct cache_tree *it,
|
||||||
i += sub->count;
|
i += sub->count;
|
||||||
sha1 = sub->cache_tree->sha1;
|
sha1 = sub->cache_tree->sha1;
|
||||||
mode = S_IFDIR;
|
mode = S_IFDIR;
|
||||||
if (sub->cache_tree->entry_count < 0) {
|
contains_ita = sub->cache_tree->entry_count < 0;
|
||||||
|
if (contains_ita) {
|
||||||
to_invalidate = 1;
|
to_invalidate = 1;
|
||||||
expected_missing = 1;
|
expected_missing = 1;
|
||||||
}
|
}
|
||||||
|
@ -380,6 +382,12 @@ static int update_one(struct cache_tree *it,
|
||||||
continue;
|
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_grow(&buffer, entlen + 100);
|
||||||
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
|
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
|
||||||
strbuf_add(&buffer, sha1, 20);
|
strbuf_add(&buffer, sha1, 20);
|
||||||
|
|
|
@ -99,5 +99,19 @@ test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'cache-tree does skip dir that becomes empty' '
|
||||||
|
rm -fr ita-in-dir &&
|
||||||
|
git init ita-in-dir &&
|
||||||
|
(
|
||||||
|
cd ita-in-dir &&
|
||||||
|
mkdir -p 1/2/3 &&
|
||||||
|
echo 4 >1/2/3/4 &&
|
||||||
|
git add -N 1/2/3/4 &&
|
||||||
|
git write-tree >actual &&
|
||||||
|
echo $EMPTY_TREE >expected &&
|
||||||
|
test_cmp expected actual
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user