summaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-02-24 04:27:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-24 20:55:42 (GMT)
commit0763671b8e0b3ef873df13c741a911b809e6813d (patch)
tree7a47629343f59d05256b72ab8d649000c7cd6745 /packfile.c
parent51ebf55b9309824346a6589c9f3b130c6f371b8f (diff)
downloadgit-0763671b8e0b3ef873df13c741a911b809e6813d.zip
git-0763671b8e0b3ef873df13c741a911b809e6813d.tar.gz
git-0763671b8e0b3ef873df13c741a911b809e6813d.tar.bz2
nth_packed_object_oid(): use customary integer return
Our nth_packed_object_sha1() function returns NULL for error. So when we wrapped it with nth_packed_object_oid(), we kept the same semantics. But it's a bit funny, because the caller actually passes in an out parameter, and the pointer we return is just that same struct they passed to us (or NULL). It's not too terrible, but it does make the interface a little non-idiomatic. Let's switch to our usual "0 for success, negative for error" return value. Most callers either don't check it, or are trivially converted. The one that requires the biggest change is actually improved, as we can ditch an extra aliased pointer variable. Since we are changing the interface in a subtle way that the compiler wouldn't catch, let's also change the name to catch any topics in flight. We can drop the 'o' and make it nth_packed_object_id(). That's slightly shorter, but also less redundant since the 'o' stands for "object" already. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/packfile.c b/packfile.c
index 99dd1a7..947c3f8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1261,7 +1261,7 @@ static int retry_bad_packed_offset(struct repository *r,
revidx = find_pack_revindex(p, obj_offset);
if (!revidx)
return OBJ_BAD;
- nth_packed_object_oid(&oid, p, revidx->nr);
+ nth_packed_object_id(&oid, p, revidx->nr);
mark_bad_packed_object(p, oid.hash);
type = oid_object_info(r, &oid, NULL);
if (type <= OBJ_NONE)
@@ -1693,7 +1693,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
off_t len = revidx[1].offset - obj_offset;
if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) {
struct object_id oid;
- nth_packed_object_oid(&oid, p, revidx->nr);
+ nth_packed_object_id(&oid, p, revidx->nr);
error("bad packed object CRC for %s",
oid_to_hex(&oid));
mark_bad_packed_object(p, oid.hash);
@@ -1782,7 +1782,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
struct object_id base_oid;
revidx = find_pack_revindex(p, obj_offset);
if (revidx) {
- nth_packed_object_oid(&base_oid, p, revidx->nr);
+ nth_packed_object_id(&base_oid, p, revidx->nr);
error("failed to read delta base object %s"
" at offset %"PRIuMAX" from %s",
oid_to_hex(&base_oid), (uintmax_t)obj_offset,
@@ -1890,15 +1890,15 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,
}
}
-const struct object_id *nth_packed_object_oid(struct object_id *oid,
- 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 *hash = nth_packed_object_sha1(p, n);
if (!hash)
- return NULL;
+ return -1;
hashcpy(oid->hash, hash);
- return oid;
+ return 0;
}
void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
@@ -2077,7 +2077,7 @@ int for_each_object_in_pack(struct packed_git *p,
else
pos = i;
- if (!nth_packed_object_oid(&oid, p, pos))
+ if (nth_packed_object_id(&oid, p, pos) < 0)
return error("unable to get sha1 of object %u in %s",
pos, p->pack_name);