Skip to content

Commit 4ef8d1d

Browse files
committed
sha1_loose_object_info(): do not return success on missing object
Since 052fe5e (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 <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d619cfc commit 4ef8d1d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

sha1_file.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,15 +2413,18 @@ static int sha1_loose_object_info(const unsigned char *sha1,
24132413

24142414
/*
24152415
* 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.
24172421
*/
24182422
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)
24232427
*oi->disk_sizep = st.st_size;
2424-
}
24252428
return 0;
24262429
}
24272430

t/t1006-cat-file.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ test_expect_success "--batch-check for an emtpy line" '
179179
test " missing" = "$(echo | git cat-file --batch-check)"
180180
'
181181

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+
182188
batch_input="$hello_sha1
183189
$commit_sha1
184190
$tag_sha1

0 commit comments

Comments
 (0)