From d5a16761820f2539bf8610c8f0c64f610e29314e Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:31 -0700 Subject: pack: move nth_packed_object_{sha1,oid} Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- packfile.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index b2a3a217d3..cc8d0d7db8 100644 --- a/packfile.c +++ b/packfile.c @@ -1636,3 +1636,34 @@ out: return data; } + +const unsigned char *nth_packed_object_sha1(struct packed_git *p, + uint32_t n) +{ + const unsigned char *index = p->index_data; + if (!index) { + if (open_pack_index(p)) + return NULL; + index = p->index_data; + } + if (n >= p->num_objects) + return NULL; + index += 4 * 256; + if (p->index_version == 1) { + return index + 24 * n + 4; + } else { + index += 8; + return index + 20 * n; + } +} + +const struct object_id *nth_packed_object_oid(struct object_id *oid, + struct packed_git *p, + uint32_t n) +{ + const unsigned char *hash = nth_packed_object_sha1(p, n); + if (!hash) + return NULL; + hashcpy(oid->hash, hash); + return oid; +} -- cgit v1.2.3