Signed-off-by: Jonathan Tan <[email protected]>
---
cache.h | 14 --------------
pack.h | 14 ++++++++++++++
packfile.c | 31 +++++++++++++++++++++++++++++++
sha1_file.c | 31 -------------------------------
4 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/cache.h b/cache.h
index b14098bf1..f083d532e 100644
--- a/cache.h
+++ b/cache.h
@@ -1628,20 +1628,6 @@ extern int odb_pack_keep(const char *name);
*/
extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
-/*
- * Return the SHA-1 of the nth object within the specified packfile.
- * Open the index if it is not already open. The return value points
- * at the SHA-1 within the mmapped index. Return NULL if there is an
- * error.
- */
-extern const unsigned char *nth_packed_object_sha1(struct packed_git *,
uint32_t n);
-/*
- * Like nth_packed_object_sha1, but write the data into the object specified by
- * the the first argument. Returns the first argument on success, and NULL on
- * error.
- */
-extern const struct object_id *nth_packed_object_oid(struct object_id *,
struct packed_git *, uint32_t n);
-
/*
* Return the offset of the nth object within the specified packfile.
* The index must already be opened.
diff --git a/pack.h b/pack.h
index 2e6f357c3..023c97b37 100644
--- a/pack.h
+++ b/pack.h
@@ -182,4 +182,18 @@ extern void *unpack_entry(struct packed_git *, off_t, enum
object_type *, unsign
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char
*sha1);
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
+/*
+ * Return the SHA-1 of the nth object within the specified packfile.
+ * Open the index if it is not already open. The return value points
+ * at the SHA-1 within the mmapped index. Return NULL if there is an
+ * error.
+ */
+extern const unsigned char *nth_packed_object_sha1(struct packed_git *,
uint32_t n);
+/*
+ * Like nth_packed_object_sha1, but write the data into the object specified by
+ * the the first argument. Returns the first argument on success, and NULL on
+ * error.
+ */
+extern const struct object_id *nth_packed_object_oid(struct object_id *,
struct packed_git *, uint32_t n);
+
#endif
diff --git a/packfile.c b/packfile.c
index a3745f9df..b16cf648a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1634,3 +1634,34 @@ void *unpack_entry(struct packed_git *p, off_t
obj_offset,
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;
+}
diff --git a/sha1_file.c b/sha1_file.c
index fe7e0db76..4cd2b1809 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1073,37 +1073,6 @@ int parse_sha1_header(const char *hdr, unsigned long
*sizep)
return parse_sha1_header_extended(hdr, &oi, 0);
}
-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;
-}
-
void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
{
const unsigned char *ptr = vptr;
--
2.14.0.434.g98096fd7a8-goog