pack-objects: read delta base oid into object_id struct
commit3f83fd5e44c1f038c8a7033cb77399e9ef4f43a9
authorJeff King <peff@peff.net>
Mon, 24 Feb 2020 04:29:44 +0000 (23 23:29 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Feb 2020 20:55:52 +0000 (24 12:55 -0800)
treed640d83f4d693682b2252817d60a3c5e19d47c44
parent0763671b8e0b3ef873df13c741a911b809e6813d
pack-objects: read delta base oid into object_id struct

When we're considering reusing an on-disk delta, we get the oid of the
base as a pointer to unsigned char bytes of the hash, either into the
packfile itself (for REF_DELTA) or into the pack idx (using the revindex
to convert the offset into an index entry).

Instead, we'd prefer to use a more type-safe object_id as much as
possible. We can get the pack idx using nth_packed_object_id() instead.
For the packfile bytes, we can copy them out using oidread().

This doesn't even incur an extra copy overall, since the next thing we'd
always do with that pointer is pass it to can_reuse_delta(), which needs
an object_id anyway (and called oidread() itself). So this patch also
converts that function to take the object_id directly.

Note that we did previously use NULL as a sentinel value when the object
isn't a delta. We could probably get away with using the null oid for
this, but instead we'll use an explicit boolean flag, which should make
things more obvious for people reading the code later.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c