summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2016-08-08 14:21:32 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-08-08 14:21:33 -0700
commit880b3fee51e9b5b0bb7c0361fd3bf2c5fedda5bf (patch)
tree8f8b8c40c0e6914a81d5ac2c3b3658389f06de10 /cache-tree.c
parentMerge branch 'mh/blame-worktree' into maint (diff)
parentcache-tree: do not generate empty trees as a result of all i-t-a subentries (diff)
downloadtgif-880b3fee51e9b5b0bb7c0361fd3bf2c5fedda5bf.tar.xz
Merge branch 'nd/cache-tree-ita' into maint
"git add -N dir/file && git write-tree" produced an incorrect tree when there are other paths in the same directory that sorts after "file". * nd/cache-tree-ita: cache-tree: do not generate empty trees as a result of all i-t-a subentries cache-tree.c: fix i-t-a entry skipping directory updates sometimes test-lib.sh: introduce and use $EMPTY_BLOB test-lib.sh: introduce and use $EMPTY_TREE
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/cache-tree.c b/cache-tree.c
index ddf0cc9f9a..f28b1f45a4 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -319,12 +319,13 @@ static int update_one(struct cache_tree *it,
i = 0;
while (i < entries) {
const struct cache_entry *ce = cache[i];
- struct cache_tree_sub *sub;
+ struct cache_tree_sub *sub = NULL;
const char *path, *slash;
int pathlen, entlen;
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;
}
@@ -375,11 +377,17 @@ static int update_one(struct cache_tree *it,
* they are not part of generated trees. Invalidate up
* to root to force cache-tree users to read elsewhere.
*/
- if (ce_intent_to_add(ce)) {
+ if (!sub && ce_intent_to_add(ce)) {
to_invalidate = 1;
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);