sha1_file: teach packed_object_info about typename
In commit 46f0344 ("sha1_file: support reading from a loose object of unknown type", 2015-05-06), "struct object_info" gained a "typename" field that could represent a type name from a loose object file, whether valid or invalid, as opposed to the existing "typep" which could only represent valid types. Some relatively complex manipulations were added to avoid breaking packed_object_info() without modifying it, but it is much easier to just teach packed_object_info() about the new field. Therefore, teach packed_object_info() as described above. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Jun 13, 2017 at 14:05 UTC
285a2984bd92a273fb85a216ec7243ea74761a12
1 file changed
+12
-17
sha1_file.c
+12
-17
@@ -2277,9 +2277,18 @@ int packed_object_info(struct packed_git *p, off_t obj_offset,
2277
*oi->disk_sizep = revidx[1].offset - obj_offset;
2278
}
2279
2280
- if (oi->typep) {
2281
- *oi->typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
2282
- if (*oi->typep < 0) {
2280
+ if (oi->typep || oi->typename) {
2281
+ enum object_type ptot;
2282
+ ptot = packed_to_object_type(p, obj_offset, type, &w_curs,
2283
+ curpos);
2284
+ if (oi->typep)
2285
+ *oi->typep = ptot;
2286
+ if (oi->typename) {
2287
+ const char *tn = typename(ptot);
2288
+ if (tn)
2289
+ strbuf_addstr(oi->typename, tn);
2290
+ }
2291
+ if (ptot < 0) {
2292
type = OBJ_BAD;
2293
goto out;
2294
}
@@ -2960,7 +2969,6 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
2969
struct cached_object *co;
2970
struct pack_entry e;
2971
int rtype;
2963
- enum object_type real_type;
2972
const unsigned char *real = lookup_replace_object_extended(sha1, flags);
2973
2974
co = find_cached_object(real);
@@ -2992,18 +3000,9 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
3000
return -1;
3001
}
3002
2995
- /*
2996
- * packed_object_info() does not follow the delta chain to
2997
- * find out the real type, unless it is given oi->typep.
2998
- */
2999
- if (oi->typename && !oi->typep)
3000
- oi->typep = &real_type;
3001
-
3003
rtype = packed_object_info(e.p, e.offset, oi);
3004
if (rtype < 0) {
3005
mark_bad_packed_object(e.p, real);
3005
- if (oi->typep == &real_type)
3006
- oi->typep = NULL;
3006
return sha1_object_info_extended(real, oi, 0);
3007
} else if (in_delta_base_cache(e.p, e.offset)) {
3008
oi->whence = OI_DBCACHED;
@@ -3014,10 +3013,6 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
3013
oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||
3014
rtype == OBJ_OFS_DELTA);
3015
}
3017
- if (oi->typename)
3018
- strbuf_addstr(oi->typename, typename(*oi->typep));
3019
- if (oi->typep == &real_type)
3020
- oi->typep = NULL;
3016
3017
return 0;
3018
}