sha1_loose_object_info(): do not return success on missing object

Since 052fe5ea (sha1_loose_object_info: make type lookup optional, 2013-07-12), sha1_loose_object_info() returns happily without checking if the object in question exists, which is not what the the caller sha1_object_info_extended() expects; the caller does not even bother checking the existence of the object itself. Noticed-by: Sven Brauch <svenbrauch@googlemail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 6, 2013 at 10:00 UTC 4ef8d1dd03d3b8adf81b4b81b2231128e3591f36
2 files changed +15 -6
sha1_file.c
+9 -6
@@ -2413,15 +2413,18 @@ static int sha1_loose_object_info(const unsigned char *sha1,
2413
2414 /*
2415 * If we don't care about type or size, then we don't
2416 - * need to look inside the object at all.
2416 + * need to look inside the object at all. Note that we
2417 + * do not optimize out the stat call, even if the
2418 + * caller doesn't care about the disk-size, since our
2419 + * return value implicitly indicates whether the
2420 + * object even exists.
2421 */
2422 if (!oi->typep && !oi->sizep) {
2419 - if (oi->disk_sizep) {
2420 - struct stat st;
2421 - if (stat_sha1_file(sha1, &st) < 0)
2422 - return -1;
2423 + struct stat st;
2424 + if (stat_sha1_file(sha1, &st) < 0)
2425 + return -1;
2426 + if (oi->disk_sizep)
2427 *oi->disk_sizep = st.st_size;
2424 - }
2428 return 0;
2429 }
2430
t/t1006-cat-file.sh
+6
@@ -179,6 +179,12 @@ test_expect_success "--batch-check for an emtpy line" '
179 test " missing" = "$(echo | git cat-file --batch-check)"
180 '
181
182 +test_expect_success 'empty --batch-check notices missing object' '
183 + echo "$_z40 missing" >expect &&
184 + echo "$_z40" | git cat-file --batch-check="" >actual &&
185 + test_cmp expect actual
186 +'
187 +
188 batch_input="$hello_sha1
189 $commit_sha1
190 $tag_sha1