Skip to content

Commit b99b6bc

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63f4a7f commit b99b6bc

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
262262
strbuf_addstr(sb, data->rest);
263263
} else if (is_atom("deltabase", atom, len)) {
264264
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;
266266
else
267267
strbuf_addstr(sb,
268268
oid_to_hex(&data->delta_base_oid));

object-store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct object_info {
300300
enum object_type *typep;
301301
unsigned long *sizep;
302302
off_t *disk_sizep;
303-
unsigned char *delta_base_sha1;
303+
struct object_id *delta_base_oid;
304304
struct strbuf *type_name;
305305
void **contentp;
306306

packfile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15561556
}
15571557
}
15581558

1559-
if (oi->delta_base_sha1) {
1559+
if (oi->delta_base_oid) {
15601560
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
15611561
const unsigned char *base;
15621562

@@ -1567,9 +1567,9 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15671567
goto out;
15681568
}
15691569

1570-
hashcpy(oi->delta_base_sha1, base);
1570+
hashcpy(oi->delta_base_oid->hash, base);
15711571
} else
1572-
hashclr(oi->delta_base_sha1);
1572+
oidclr(oi->delta_base_oid);
15731573
}
15741574

15751575
oi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :

ref-filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ static int deltabase_atom_parser(const struct ref_format *format, struct used_at
279279
if (arg)
280280
return strbuf_addf_ret(err, -1, _("%%(deltabase) does not take arguments"));
281281
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;
283283
else
284-
oi.info.delta_base_sha1 = oi.delta_base_oid.hash;
284+
oi.info.delta_base_oid = &oi.delta_base_oid;
285285
return 0;
286286
}
287287

sha1-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,8 +1354,8 @@ static int loose_object_info(struct repository *r,
13541354
struct strbuf hdrbuf = STRBUF_INIT;
13551355
unsigned long size_scratch;
13561356

1357-
if (oi->delta_base_sha1)
1358-
hashclr(oi->delta_base_sha1);
1357+
if (oi->delta_base_oid)
1358+
oidclr(oi->delta_base_oid);
13591359

13601360
/*
13611361
* 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,
14741474
*(oi->sizep) = co->size;
14751475
if (oi->disk_sizep)
14761476
*(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);
14791479
if (oi->type_name)
14801480
strbuf_addstr(oi->type_name, type_name(co->type));
14811481
if (oi->contentp)

0 commit comments

Comments
 (0)