]> git.ipfire.org Git - thirdparty/git.git/blobdiff - packfile.c
pack: move nth_packed_object_{sha1,oid}
[thirdparty/git.git] / packfile.c
index b2a3a217d362f515b9c33040c5f6bcadb5cb6235..cc8d0d7db8777d6c933f135fb9722f9e15ed888a 100644 (file)
@@ -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;
+}