Skip to content

Commit 1f7117e

Browse files
chriscoolgitster
authored andcommitted
sha1_file: perform object replacement in sha1_object_info_extended()
sha1_object_info_extended() should perform object replacement if it is needed. The simplest way to do that is to make it call lookup_replace_object_extended(). And now its "unsigned flags" parameter is used as it is passed to lookup_replace_object_extended(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 303c5d6 commit 1f7117e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

sha1_file.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,8 +2519,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
25192519
struct cached_object *co;
25202520
struct pack_entry e;
25212521
int rtype;
2522+
const unsigned char *real = lookup_replace_object_extended(sha1, flags);
25222523

2523-
co = find_cached_object(sha1);
2524+
co = find_cached_object(real);
25242525
if (co) {
25252526
if (oi->typep)
25262527
*(oi->typep) = co->type;
@@ -2532,23 +2533,23 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
25322533
return 0;
25332534
}
25342535

2535-
if (!find_pack_entry(sha1, &e)) {
2536+
if (!find_pack_entry(real, &e)) {
25362537
/* Most likely it's a loose object. */
2537-
if (!sha1_loose_object_info(sha1, oi)) {
2538+
if (!sha1_loose_object_info(real, oi)) {
25382539
oi->whence = OI_LOOSE;
25392540
return 0;
25402541
}
25412542

25422543
/* Not a loose object; someone else may have just packed it. */
25432544
reprepare_packed_git();
2544-
if (!find_pack_entry(sha1, &e))
2545+
if (!find_pack_entry(real, &e))
25452546
return -1;
25462547
}
25472548

25482549
rtype = packed_object_info(e.p, e.offset, oi);
25492550
if (rtype < 0) {
2550-
mark_bad_packed_object(e.p, sha1);
2551-
return sha1_object_info_extended(sha1, oi, 0);
2551+
mark_bad_packed_object(e.p, real);
2552+
return sha1_object_info_extended(real, oi, 0);
25522553
} else if (in_delta_base_cache(e.p, e.offset)) {
25532554
oi->whence = OI_DBCACHED;
25542555
} else {

t/t6050-replace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ test_expect_success '-f option bypasses the type check' '
276276
git replace -f HEAD^ $BLOB
277277
'
278278

279-
test_expect_failure 'git cat-file --batch works on replace objects' '
279+
test_expect_success 'git cat-file --batch works on replace objects' '
280280
git replace | grep $PARA3 &&
281281
echo $PARA3 | git cat-file --batch
282282
'

0 commit comments

Comments
 (0)