diff options
authorJeff King <>2020-02-24 04:31:22 (GMT)
committerJunio C Hamano <>2020-02-24 20:55:53 (GMT)
commitf66d4e025059b734ba8da40ec059bb0fb8991306 (patch)
parenta93c141ddef25dc999fff73c590b42d3af606ff3 (diff)
pack-objects: use object_id struct in pack-reuse code
When the pack-reuse code is dumping an OFS_DELTA entry to a client that doesn't support it, we re-write it as a REF_DELTA. To do so, we use nth_packed_object_sha1() to get the oid, but that function is soon going away in favor of the more type-safe nth_packed_object_id(). Let's switch now in preparation. Note that this does incur an extra hash copy (from the pack idx mmap to the object_id and then to the output, rather than straight from mmap to the output). But this is not worth worrying about. It's probably not measurable even when it triggers, and this is fallback code that we expect to trigger very rarely (since everybody supports OFS_DELTA these days anyway). Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
1 files changed, 5 insertions, 4 deletions
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 44f44fc..73fca2c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -872,14 +872,15 @@ static void write_reused_pack_one(size_t pos, struct hashfile *out,
/* Convert to REF_DELTA if we must... */
if (!allow_ofs_delta) {
int base_pos = find_revindex_position(reuse_packfile, base_offset);
- const unsigned char *base_sha1 =
- nth_packed_object_sha1(reuse_packfile,
- reuse_packfile->revindex[base_pos].nr);
+ struct object_id base_oid;
+ nth_packed_object_id(&base_oid, reuse_packfile,
+ reuse_packfile->revindex[base_pos].nr);
len = encode_in_pack_object_header(header, sizeof(header),
hashwrite(out, header, len);
- hashwrite(out, base_sha1, 20);
+ hashwrite(out, base_oid.hash, 20);
copy_pack_data(out, reuse_packfile, w_curs, cur, next - cur);