Skip to content

Commit

Permalink
sha1_loose_object_info(): do not return success on missing object
Browse files Browse the repository at this point in the history
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 <svenbrauch@googlemail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Nov 6, 2013
1 parent d619cfc commit 4ef8d1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2413,15 +2413,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;
}

Expand Down
6 changes: 6 additions & 0 deletions t/t1006-cat-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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
Expand Down

0 comments on commit 4ef8d1d

Please sign in to comment.