aboutsummaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-08-18 15:20:31 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-23 15:12:07 -0700
commitd5a16761820f2539bf8610c8f0c64f610e29314e (patch)
tree4081ca185c262f7a2b6acec8c830a4172789e720 /packfile.c
parentf1d8130be0a7229b215b76eac54c561a0124bc99 (diff)
downloadgit-d5a16761820f2539bf8610c8f0c64f610e29314e.tar.gz
git-d5a16761820f2539bf8610c8f0c64f610e29314e.tar.xz
pack: move nth_packed_object_{sha1,oid}
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/packfile.c b/packfile.c
index b2a3a217d..cc8d0d7db 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;
+}