Skip to content

Commit f66d4e0

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

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin/pack-objects.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,14 +872,15 @@ static void write_reused_pack_one(size_t pos, struct hashfile *out,
872872
/* Convert to REF_DELTA if we must... */
873873
if (!allow_ofs_delta) {
874874
int base_pos = find_revindex_position(reuse_packfile, base_offset);
875-
const unsigned char *base_sha1 =
876-
nth_packed_object_sha1(reuse_packfile,
877-
reuse_packfile->revindex[base_pos].nr);
875+
struct object_id base_oid;
876+
877+
nth_packed_object_id(&base_oid, reuse_packfile,
878+
reuse_packfile->revindex[base_pos].nr);
878879

879880
len = encode_in_pack_object_header(header, sizeof(header),
880881
OBJ_REF_DELTA, size);
881882
hashwrite(out, header, len);
882-
hashwrite(out, base_sha1, 20);
883+
hashwrite(out, base_oid.hash, 20);
883884
copy_pack_data(out, reuse_packfile, w_curs, cur, next - cur);
884885
return;
885886
}

0 commit comments

Comments
 (0)