cache-tree: do not try to use an invalidated subtree info to build a tree
authorJunio C Hamano <gitster@pobox.com>
Tue, 2 Sep 2014 21:16:20 +0000 (14:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Sep 2014 17:21:33 +0000 (10:21 -0700)
We punt from repairing the cache-tree during a branch switching if
it involves having to create a new tree object that does not yet
exist in the object store. "mkdir dir && >dir/file && git add dir"
followed by "git checkout" is one example, when a tree that records
the state of such "dir/" is not in the object store.

However, after discovering that we do not have a tree object that
records the state of "dir/", the caller failed to remember the fact
that it noticed the cache-tree entry it received for "dir/" is
invalidated, it already knows it should not be populating the level
that has "dir/" as its immediate subdirectory, and it is not an
error at all for the sublevel cache-tree entry gave it a bogus
object name it shouldn't even look at.

This led the caller to detect and report a non-existent error. The
end result was the same and we avoided stuffing a non-existent tree
to the cache-tree, but we shouldn't have issued an alarming error
message to the user.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache-tree.c
t/t0090-cache-tree.sh
index f951d7d3c4d8ec8f67c896d835cef16b74c6f171..57597ac8b13e6d681913b2b40098c429a08fd71f 100644 (file)
@@ -316,6 +316,7 @@ static int update_one(struct cache_tree *it,
                int pathlen, entlen;
                const unsigned char *sha1;
                unsigned mode;
+               int expected_missing = 0;
 
                path = ce->name;
                pathlen = ce_namelen(ce);
@@ -332,8 +333,10 @@ 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)
+                       if (sub->cache_tree->entry_count < 0) {
                                to_invalidate = 1;
+                               expected_missing = 1;
+                       }
                }
                else {
                        sha1 = ce->sha1;
@@ -343,6 +346,8 @@ static int update_one(struct cache_tree *it,
                }
                if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
                        strbuf_release(&buffer);
+                       if (expected_missing)
+                               return -1;
                        return error("invalid object %06o %s for '%.*s'",
                                mode, sha1_to_hex(sha1), entlen+baselen, path);
                }
index 48c42409d2f0bbc17fa54472b046b968434c2a93..f9648a86426470785159b5132305a256c80b5ca4 100755 (executable)
@@ -210,4 +210,12 @@ test_expect_success 'partial commit gives cache-tree' '
        test_cache_tree
 '
 
+test_expect_success 'no phantom error when switching trees' '
+       mkdir newdir &&
+       >newdir/one &&
+       git add newdir/one &&
+       git checkout 2>errors &&
+       ! test -s errors
+'
+
 test_done