@matheusbsbs / matheus-bagliano / commits / 6ac9760a30
Fork 0

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>

Jeff King committed Feb 23, 2020 at 23:37 UTC 6ac9760a30683a24e80a7aefe30e383046e810f0
1 file changed +15 -17
packfile.c
+15 -17
@@ -1225,30 +1225,32 @@ off_t get_delta_base(struct packed_git *p,
1225 * the final object lookup), but more expensive for OFS deltas (we
1226 * have to load the revidx to convert the offset back into a sha1).
1227 */
1228 -static const unsigned char *get_delta_base_sha1(struct packed_git *p,
1229 - struct pack_window **w_curs,
1230 - off_t curpos,
1231 - enum object_type type,
1232 - off_t delta_obj_offset)
1228 +static int get_delta_base_oid(struct packed_git *p,
1229 + struct pack_window **w_curs,
1230 + off_t curpos,
1231 + struct object_id *oid,
1232 + enum object_type type,
1233 + off_t delta_obj_offset)
1234 {
1235 if (type == OBJ_REF_DELTA) {
1236 unsigned char *base = use_pack(p, w_curs, curpos, NULL);
1236 - return base;
1237 + oidread(oid, base);
1238 + return 0;
1239 } else if (type == OBJ_OFS_DELTA) {
1240 struct revindex_entry *revidx;
1241 off_t base_offset = get_delta_base(p, w_curs, &curpos,
1242 type, delta_obj_offset);
1243
1244 if (!base_offset)
1243 - return NULL;
1245 + return -1;
1246
1247 revidx = find_pack_revindex(p, base_offset);
1248 if (!revidx)
1247 - return NULL;
1249 + return -1;
1250
1249 - return nth_packed_object_sha1(p, revidx->nr);
1251 + return nth_packed_object_id(oid, p, revidx->nr);
1252 } else
1251 - return NULL;
1253 + return -1;
1254 }
1255
1256 static int retry_bad_packed_offset(struct repository *r,
@@ -1558,16 +1560,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
1560
1561 if (oi->delta_base_oid) {
1562 if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
1561 - const unsigned char *base;
1562 -
1563 - base = get_delta_base_sha1(p, &w_curs, curpos,
1564 - type, obj_offset);
1565 - if (!base) {
1563 + if (get_delta_base_oid(p, &w_curs, curpos,
1564 + oi->delta_base_oid,
1565 + type, obj_offset) < 0) {
1566 type = OBJ_BAD;
1567 goto out;
1568 }
1569 -
1570 - hashcpy(oi->delta_base_oid->hash, base);
1569 } else
1570 oidclr(oi->delta_base_oid);
1571 }