summaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-02-24 04:37:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-24 20:55:53 (GMT)
commit6ac9760a30683a24e80a7aefe30e383046e810f0 (patch)
treec1cb67476879ddda783e6a8df7a43344f4253841 /packfile.c
parentb99b6bcc57faf5c989fc18c3b8d4d92df3407cec (diff)
downloadgit-6ac9760a30683a24e80a7aefe30e383046e810f0.zip
git-6ac9760a30683a24e80a7aefe30e383046e810f0.tar.gz
git-6ac9760a30683a24e80a7aefe30e383046e810f0.tar.bz2
packed_object_info(): use object_id internally for delta base
The previous commit changed the public interface of packed_object_info() to return a struct object_id rather than a bare hash. That enables us to convert our internal helper, as well. We can use nth_packed_object_id() directly for OFS_DELTA, but we'll still have to use oidread() to pull the hash for a REF_DELTA out of the packfile. There should be no additional cost, since we're copying directly into the object_id the caller provided us (just as we did before; it's just happening now via nth_packed_object_id()). 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.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/packfile.c b/packfile.c
index ec7349b..90cb5a0 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1225,30 +1225,32 @@ off_t get_delta_base(struct packed_git *p,
* the final object lookup), but more expensive for OFS deltas (we
* have to load the revidx to convert the offset back into a sha1).
*/
-static const unsigned char *get_delta_base_sha1(struct packed_git *p,
- struct pack_window **w_curs,
- off_t curpos,
- enum object_type type,
- off_t delta_obj_offset)
+static int get_delta_base_oid(struct packed_git *p,
+ struct pack_window **w_curs,
+ off_t curpos,
+ struct object_id *oid,
+ enum object_type type,
+ off_t delta_obj_offset)
{
if (type == OBJ_REF_DELTA) {
unsigned char *base = use_pack(p, w_curs, curpos, NULL);
- return base;
+ oidread(oid, base);
+ return 0;
} else if (type == OBJ_OFS_DELTA) {
struct revindex_entry *revidx;
off_t base_offset = get_delta_base(p, w_curs, &curpos,
type, delta_obj_offset);
if (!base_offset)
- return NULL;
+ return -1;
revidx = find_pack_revindex(p, base_offset);
if (!revidx)
- return NULL;
+ return -1;
- return nth_packed_object_sha1(p, revidx->nr);
+ return nth_packed_object_id(oid, p, revidx->nr);
} else
- return NULL;
+ return -1;
}
static int retry_bad_packed_offset(struct repository *r,
@@ -1558,16 +1560,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
if (oi->delta_base_oid) {
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
- const unsigned char *base;
-
- base = get_delta_base_sha1(p, &w_curs, curpos,
- type, obj_offset);
- if (!base) {
+ if (get_delta_base_oid(p, &w_curs, curpos,
+ oi->delta_base_oid,
+ type, obj_offset) < 0) {
type = OBJ_BAD;
goto out;
}
-
- hashcpy(oi->delta_base_oid->hash, base);
} else
oidclr(oi->delta_base_oid);
}