Merge branch 'sb/sha1-loose-object-info-check-existence' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Dec 2013 19:31:18 +0000 (11:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Dec 2013 19:31:18 +0000 (11:31 -0800)
"git cat-file --batch-check=ok" did not check the existence of the
named object.

* sb/sha1-loose-object-info-check-existence:
sha1_loose_object_info(): do not return success on missing object

sha1_file.c
t/t1006-cat-file.sh
index 7dadd04cb75a9f681cab17f616600cf437fe82ba..9ae98c852c862679a064af34aa4d43141db7cc0c 100644 (file)
@@ -2483,15 +2483,18 @@ static int sha1_loose_object_info(const unsigned char *sha1,
 
        /*
         * If we don't care about type or size, then we don't
-        * need to look inside the object at all.
+        * need to look inside the object at all. Note that we
+        * do not optimize out the stat call, even if the
+        * caller doesn't care about the disk-size, since our
+        * return value implicitly indicates whether the
+        * object even exists.
         */
        if (!oi->typep && !oi->sizep) {
-               if (oi->disk_sizep) {
-                       struct stat st;
-                       if (stat_sha1_file(sha1, &st) < 0)
-                               return -1;
+               struct stat st;
+               if (stat_sha1_file(sha1, &st) < 0)
+                       return -1;
+               if (oi->disk_sizep)
                        *oi->disk_sizep = st.st_size;
-               }
                return 0;
        }
 
index a420742494024e127d4e4233153c7054e077e471..8a1bc5c53281eb6f44c15d68dd0ae737bc0125f3 100755 (executable)
@@ -194,6 +194,12 @@ test_expect_success "--batch-check for an emtpy line" '
     test " missing" = "$(echo | git cat-file --batch-check)"
 '
 
+test_expect_success 'empty --batch-check notices missing object' '
+       echo "$_z40 missing" >expect &&
+       echo "$_z40" | git cat-file --batch-check="" >actual &&
+       test_cmp expect actual
+'
+
 batch_input="$hello_sha1
 $commit_sha1
 $tag_sha1