packed_object_info(): use object_id for returning delta base
If a caller sets the object_info.delta_base_sha1 to a non-NULL pointer, we'll write the oid of the object's delta base to it. But we can increase our type safety by switching this to a real object_id struct. All of our callers are just pointing into the hash member of an object_id anyway, so there's no inconvenience. Note that we do still keep it as a pointer-to-struct, because the NULL sentinel value tells us whether the caller is even interested in the information. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 23, 2020 at 23:36 UTC
b99b6bcc57faf5c989fc18c3b8d4d92df3407cec
5 files changed
+11
-11
builtin/cat-file.c
+1
-1
@@ -262,7 +262,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
262
strbuf_addstr(sb, data->rest);
263
} else if (is_atom("deltabase", atom, len)) {
264
if (data->mark_query)
265
- data->info.delta_base_sha1 = data->delta_base_oid.hash;
265
+ data->info.delta_base_oid = &data->delta_base_oid;
266
else
267
strbuf_addstr(sb,
268
oid_to_hex(&data->delta_base_oid));
object-store.h
+1
-1
@@ -300,7 +300,7 @@ struct object_info {
300
enum object_type *typep;
301
unsigned long *sizep;
302
off_t *disk_sizep;
303
- unsigned char *delta_base_sha1;
303
+ struct object_id *delta_base_oid;
304
struct strbuf *type_name;
305
void **contentp;
306
packfile.c
+3
-3
@@ -1556,7 +1556,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
1556
}
1557
}
1558
1559
- if (oi->delta_base_sha1) {
1559
+ if (oi->delta_base_oid) {
1560
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
1561
const unsigned char *base;
1562
@@ -1567,9 +1567,9 @@ int packed_object_info(struct repository *r, struct packed_git *p,
1567
goto out;
1568
}
1569
1570
- hashcpy(oi->delta_base_sha1, base);
1570
+ hashcpy(oi->delta_base_oid->hash, base);
1571
} else
1572
- hashclr(oi->delta_base_sha1);
1572
+ oidclr(oi->delta_base_oid);
1573
}
1574
1575
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :
ref-filter.c
+2
-2
@@ -279,9 +279,9 @@ static int deltabase_atom_parser(const struct ref_format *format, struct used_at
279
if (arg)
280
return strbuf_addf_ret(err, -1, _("%%(deltabase) does not take arguments"));
281
if (*atom->name == '*')
282
- oi_deref.info.delta_base_sha1 = oi_deref.delta_base_oid.hash;
282
+ oi_deref.info.delta_base_oid = &oi_deref.delta_base_oid;
283
else
284
- oi.info.delta_base_sha1 = oi.delta_base_oid.hash;
284
+ oi.info.delta_base_oid = &oi.delta_base_oid;
285
return 0;
286
}
287
sha1-file.c
+4
-4
@@ -1354,8 +1354,8 @@ static int loose_object_info(struct repository *r,
1354
struct strbuf hdrbuf = STRBUF_INIT;
1355
unsigned long size_scratch;
1356
1357
- if (oi->delta_base_sha1)
1358
- hashclr(oi->delta_base_sha1);
1357
+ if (oi->delta_base_oid)
1358
+ oidclr(oi->delta_base_oid);
1359
1360
/*
1361
* If we don't care about type or size, then we don't
@@ -1474,8 +1474,8 @@ static int do_oid_object_info_extended(struct repository *r,
1474
*(oi->sizep) = co->size;
1475
if (oi->disk_sizep)
1476
*(oi->disk_sizep) = 0;
1477
- if (oi->delta_base_sha1)
1478
- hashclr(oi->delta_base_sha1);
1477
+ if (oi->delta_base_oid)
1478
+ oidclr(oi->delta_base_oid);
1479
if (oi->type_name)
1480
strbuf_addstr(oi->type_name, type_name(co->type));
1481
if (oi->contentp)