aboutsummaryrefslogtreecommitdiffstats
path: root/packfile.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-10-25 03:06:06 -0400
committerTaylor Blau <me@ttaylorr.com>2024-10-25 17:35:46 -0400
commit479ab76c9ffbd35585a1506ac5c99fe218df70b9 (patch)
tree9e3218c9573b0b45ca5e90e4e5660cfa18592b6c /packfile.c
parentpackfile: convert find_sha1_pack() to use object_id (diff)
downloadgit-479ab76c9ffbd35585a1506ac5c99fe218df70b9.tar.gz
git-479ab76c9ffbd35585a1506ac5c99fe218df70b9.zip
packfile: use object_id in find_pack_entry_one()
The main function we use to search a pack index for an object is find_pack_entry_one(). That function still takes a bare pointer to the hash, despite the fact that its underlying bsearch_pack() function needs an object_id struct. And so we end up making an extra copy of the hash into the struct just to do a lookup. As it turns out, all callers but one already have such an object_id. So we can just take a pointer to that struct and use it directly. This avoids the extra copy and provides a more type-safe interface. The one exception is get_delta_base() in packfile.c, when we are chasing a REF_DELTA from inside the pack (and thus we have a pointer directly to the mmap'd pack memory, not a struct). We can just bump the hashcpy() from inside find_pack_entry_one() to this one caller that needs it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/packfile.c b/packfile.c
index c51eab15a5..005ca670b4 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1239,7 +1239,9 @@ off_t get_delta_base(struct packed_git *p,
*curpos += used;
} else if (type == OBJ_REF_DELTA) {
/* The base entry _must_ be in the same pack */
- base_offset = find_pack_entry_one(base_info, p);
+ struct object_id oid;
+ hashcpy(oid.hash, base_info, the_repository->hash_algo);
+ base_offset = find_pack_entry_one(&oid, p);
*curpos += the_hash_algo->rawsz;
} else
die("I am totally screwed");
@@ -1971,11 +1973,10 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
}
}
-off_t find_pack_entry_one(const unsigned char *sha1,
- struct packed_git *p)
+off_t find_pack_entry_one(const struct object_id *oid,
+ struct packed_git *p)
{
const unsigned char *index = p->index_data;
- struct object_id oid;
uint32_t result;
if (!index) {
@@ -1983,8 +1984,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
return 0;
}
- hashcpy(oid.hash, sha1, the_repository->hash_algo);
- if (bsearch_pack(&oid, p, &result))
+ if (bsearch_pack(oid, p, &result))
return nth_packed_object_offset(p, result);
return 0;
}
@@ -2016,7 +2016,7 @@ struct packed_git *find_oid_pack(const struct object_id *oid,
struct packed_git *p;
for (p = packs; p; p = p->next) {
- if (find_pack_entry_one(oid->hash, p))
+ if (find_pack_entry_one(oid, p))
return p;
}
return NULL;
@@ -2033,7 +2033,7 @@ static int fill_pack_entry(const struct object_id *oid,
oidset_contains(&p->bad_objects, oid))
return 0;
- offset = find_pack_entry_one(oid->hash, p);
+ offset = find_pack_entry_one(oid, p);
if (!offset)
return 0;