Skip to content

Commit 66c24cd

Browse files
committed
Merge branch 'sb/sha1-loose-object-info-check-existence' into maint
"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
2 parents c8b928d + 4ef8d1d commit 66c24cd

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
@@ -2483,15 +2483,18 @@ static int sha1_loose_object_info(const unsigned char *sha1,
24832483

24842484
/*
24852485
* If we don't care about type or size, then we don't
2486-
* need to look inside the object at all.
2486+
* need to look inside the object at all. Note that we
2487+
* do not optimize out the stat call, even if the
2488+
* caller doesn't care about the disk-size, since our
2489+
* return value implicitly indicates whether the
2490+
* object even exists.
24872491
*/
24882492
if (!oi->typep && !oi->sizep) {
2489-
if (oi->disk_sizep) {
2490-
struct stat st;
2491-
if (stat_sha1_file(sha1, &st) < 0)
2492-
return -1;
2493+
struct stat st;
2494+
if (stat_sha1_file(sha1, &st) < 0)
2495+
return -1;
2496+
if (oi->disk_sizep)
24932497
*oi->disk_sizep = st.st_size;
2494-
}
24952498
return 0;
24962499
}
24972500

t/t1006-cat-file.sh

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

197+
test_expect_success 'empty --batch-check notices missing object' '
198+
echo "$_z40 missing" >expect &&
199+
echo "$_z40" | git cat-file --batch-check="" >actual &&
200+
test_cmp expect actual
201+
'
202+
197203
batch_input="$hello_sha1
198204
$commit_sha1
199205
$tag_sha1

0 commit comments

Comments
 (0)