sha1_file: set whence in storage-specific info fn
Move the setting of oi->whence to sha1_loose_object_info() and packed_object_info(). This allows sha1_object_info_extended() to not need to know about the delta base cache. This will be useful during a future refactoring in which packfile-related functions, including the handling of the delta base cache, will be moved to a separate file. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Aug 11, 2017 at 13:36 UTC
3ab0fb0646d25266ec5bebd1420f691fc5a13d8a
1 file changed
+6
-7
sha1_file.c
+6
-7
@@ -2444,6 +2444,9 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,
2444
hashclr(oi->delta_base_sha1);
2445
}
2446
2447
+ oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
2448
+ OI_PACKED;
2449
+
2450
out:
2451
unuse_pack(&w_curs);
2452
return type;
@@ -2973,6 +2976,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
2976
if (oi->sizep == &size_scratch)
2977
oi->sizep = NULL;
2978
strbuf_release(&hdrbuf);
2979
+ oi->whence = OI_LOOSE;
2980
return (status < 0) ? status : 0;
2981
}
2982
@@ -3010,10 +3014,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
3014
3015
if (!find_pack_entry(real, &e)) {
3016
/* Most likely it's a loose object. */
3013
- if (!sha1_loose_object_info(real, oi, flags)) {
3014
- oi->whence = OI_LOOSE;
3017
+ if (!sha1_loose_object_info(real, oi, flags))
3018
return 0;
3016
- }
3019
3020
/* Not a loose object; someone else may have just packed it. */
3021
if (flags & OBJECT_INFO_QUICK) {
@@ -3036,10 +3038,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
3038
if (rtype < 0) {
3039
mark_bad_packed_object(e.p, real);
3040
return sha1_object_info_extended(real, oi, 0);
3039
- } else if (in_delta_base_cache(e.p, e.offset)) {
3040
- oi->whence = OI_DBCACHED;
3041
- } else {
3042
- oi->whence = OI_PACKED;
3041
+ } else if (oi->whence == OI_PACKED) {
3042
oi->u.packed.offset = e.offset;
3043
oi->u.packed.pack = e.p;
3044
oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||