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>

Christian Couder committed Dec 11, 2013 at 08:46 UTC 1f7117ef7a39ff359a964e681f360f50d7a1c8f2
2 files changed +8 -7
sha1_file.c
+7 -6
@@ -2519,8 +2519,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
2519 struct cached_object *co;
2520 struct pack_entry e;
2521 int rtype;
2522 + const unsigned char *real = lookup_replace_object_extended(sha1, flags);
2523
2523 - co = find_cached_object(sha1);
2524 + co = find_cached_object(real);
2525 if (co) {
2526 if (oi->typep)
2527 *(oi->typep) = co->type;
@@ -2532,23 +2533,23 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
2533 return 0;
2534 }
2535
2535 - if (!find_pack_entry(sha1, &e)) {
2536 + if (!find_pack_entry(real, &e)) {
2537 /* Most likely it's a loose object. */
2537 - if (!sha1_loose_object_info(sha1, oi)) {
2538 + if (!sha1_loose_object_info(real, oi)) {
2539 oi->whence = OI_LOOSE;
2540 return 0;
2541 }
2542
2543 /* Not a loose object; someone else may have just packed it. */
2544 reprepare_packed_git();
2544 - if (!find_pack_entry(sha1, &e))
2545 + if (!find_pack_entry(real, &e))
2546 return -1;
2547 }
2548
2549 rtype = packed_object_info(e.p, e.offset, oi);
2550 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);
2553 } else if (in_delta_base_cache(e.p, e.offset)) {
2554 oi->whence = OI_DBCACHED;
2555 } else {
t/t6050-replace.sh
+1 -1
@@ -276,7 +276,7 @@ test_expect_success '-f option bypasses the type check' '
276 git replace -f HEAD^ $BLOB
277 '
278
279 -test_expect_failure 'git cat-file --batch works on replace objects' '
279 +test_expect_success 'git cat-file --batch works on replace objects' '
280 git replace | grep $PARA3 &&
281 echo $PARA3 | git cat-file --batch
282 '