@matheusbsbs / matheus-bagliano / commits / 2fecc48cad
Fork 0

packfile: drop nth_packed_object_sha1()

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>

Jeff King committed Feb 23, 2020 at 23:37 UTC 2fecc48cade44529dff2594eadfb294643cdc24d
2 files changed +10 -25
packfile.c
+7 -16
@@ -1867,35 +1867,26 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32
1867 index_lookup, index_lookup_width, result);
1868 }
1869
1870 -const unsigned char *nth_packed_object_sha1(struct packed_git *p,
1871 - uint32_t n)
1870 +int nth_packed_object_id(struct object_id *oid,
1871 + struct packed_git *p,
1872 + uint32_t n)
1873 {
1874 const unsigned char *index = p->index_data;
1875 const unsigned int hashsz = the_hash_algo->rawsz;
1876 if (!index) {
1877 if (open_pack_index(p))
1877 - return NULL;
1878 + return -1;
1879 index = p->index_data;
1880 }
1881 if (n >= p->num_objects)
1881 - return NULL;
1882 + return -1;
1883 index += 4 * 256;
1884 if (p->index_version == 1) {
1884 - return index + (hashsz + 4) * n + 4;
1885 + oidread(oid, index + (hashsz + 4) * n + 4);
1886 } else {
1887 index += 8;
1887 - return index + hashsz * n;
1888 + oidread(oid, index + hashsz * n);
1889 }
1889 -}
1890 -
1891 -int nth_packed_object_id(struct object_id *oid,
1892 - struct packed_git *p,
1893 - uint32_t n)
1894 -{
1895 - const unsigned char *hash = nth_packed_object_sha1(p, n);
1896 - if (!hash)
1897 - return -1;
1898 - hashcpy(oid->hash, hash);
1890 return 0;
1891 }
1892
packfile.h
+3 -9
@@ -121,15 +121,9 @@ void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
121 int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result);
122
123 /*
124 - * Return the SHA-1 of the nth object within the specified packfile.
125 - * Open the index if it is not already open. The return value points
126 - * at the SHA-1 within the mmapped index. Return NULL if there is an
127 - * error.
128 - */
129 -const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
130 -/*
131 - * Like nth_packed_object_sha1, but write the data into the object specified by
132 - * the the first argument. Returns 0 on success, negative otherwise.
124 + * Write the oid of the nth object within the specified packfile into the first
125 + * parameter. Open the index if it is not already open. Returns 0 on success,
126 + * negative otherwise.
127 */
128 int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n);
129