]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: drop nth_packed_object_sha1()
authorJeff King <peff@peff.net>
Mon, 24 Feb 2020 04:37:54 +0000 (23:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Feb 2020 20:55:53 +0000 (12:55 -0800)
Once upon a time, nth_packed_object_sha1() was the primary way to get
the oid of a packfile's index position. But these days we have the more
type-safe nth_packed_object_id() wrapper, and all callers have been
converted.

Let's drop the "sha1" version (turning the safer wrapper into a single
function) so that nobody is tempted to introduce new callers.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c
packfile.h

index 90cb5a05ac824ab8b73d5f58e8bee95cbc51fb39..f4e752996dbcca3778c42de1d55d856a28be974d 100644 (file)
@@ -1867,35 +1867,26 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32
                            index_lookup, index_lookup_width, result);
 }
 
-const unsigned char *nth_packed_object_sha1(struct packed_git *p,
-                                           uint32_t n)
+int nth_packed_object_id(struct object_id *oid,
+                        struct packed_git *p,
+                        uint32_t n)
 {
        const unsigned char *index = p->index_data;
        const unsigned int hashsz = the_hash_algo->rawsz;
        if (!index) {
                if (open_pack_index(p))
-                       return NULL;
+                       return -1;
                index = p->index_data;
        }
        if (n >= p->num_objects)
-               return NULL;
+               return -1;
        index += 4 * 256;
        if (p->index_version == 1) {
-               return index + (hashsz + 4) * n + 4;
+               oidread(oid, index + (hashsz + 4) * n + 4);
        } else {
                index += 8;
-               return index + hashsz * n;
+               oidread(oid, index + hashsz * n);
        }
-}
-
-int nth_packed_object_id(struct object_id *oid,
-                        struct packed_git *p,
-                        uint32_t n)
-{
-       const unsigned char *hash = nth_packed_object_sha1(p, n);
-       if (!hash)
-               return -1;
-       hashcpy(oid->hash, hash);
        return 0;
 }
 
index 95b83ba25bc2459cbc6971c31b8a9d92e10988e8..240aa73b95a64912fb2cde5be049f57d91e53b84 100644 (file)
@@ -121,15 +121,9 @@ void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
 int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result);
 
 /*
- * 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.
- */
-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 0 on success, negative otherwise.
+ * Write the oid of the nth object within the specified packfile into the first
+ * parameter. Open the index if it is not already open.  Returns 0 on success,
+ * negative otherwise.
  */
 int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n);