Skip to content

Commit 2fecc48

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ac9760 commit 2fecc48

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

packfile.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,35 +1867,26 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32
18671867
index_lookup, index_lookup_width, result);
18681868
}
18691869

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)
18721873
{
18731874
const unsigned char *index = p->index_data;
18741875
const unsigned int hashsz = the_hash_algo->rawsz;
18751876
if (!index) {
18761877
if (open_pack_index(p))
1877-
return NULL;
1878+
return -1;
18781879
index = p->index_data;
18791880
}
18801881
if (n >= p->num_objects)
1881-
return NULL;
1882+
return -1;
18821883
index += 4 * 256;
18831884
if (p->index_version == 1) {
1884-
return index + (hashsz + 4) * n + 4;
1885+
oidread(oid, index + (hashsz + 4) * n + 4);
18851886
} else {
18861887
index += 8;
1887-
return index + hashsz * n;
1888+
oidread(oid, index + hashsz * n);
18881889
}
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);
18991890
return 0;
19001891
}
19011892

packfile.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,9 @@ void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
121121
int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32_t *result);
122122

123123
/*
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.
133127
*/
134128
int nth_packed_object_id(struct object_id *, struct packed_git *, uint32_t n);
135129

0 commit comments

Comments
 (0)