Skip to content

Commit 6ac9760

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

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

packfile.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,30 +1225,32 @@ off_t get_delta_base(struct packed_git *p,
12251225
* the final object lookup), but more expensive for OFS deltas (we
12261226
* have to load the revidx to convert the offset back into a sha1).
12271227
*/
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)
12331234
{
12341235
if (type == OBJ_REF_DELTA) {
12351236
unsigned char *base = use_pack(p, w_curs, curpos, NULL);
1236-
return base;
1237+
oidread(oid, base);
1238+
return 0;
12371239
} else if (type == OBJ_OFS_DELTA) {
12381240
struct revindex_entry *revidx;
12391241
off_t base_offset = get_delta_base(p, w_curs, &curpos,
12401242
type, delta_obj_offset);
12411243

12421244
if (!base_offset)
1243-
return NULL;
1245+
return -1;
12441246

12451247
revidx = find_pack_revindex(p, base_offset);
12461248
if (!revidx)
1247-
return NULL;
1249+
return -1;
12481250

1249-
return nth_packed_object_sha1(p, revidx->nr);
1251+
return nth_packed_object_id(oid, p, revidx->nr);
12501252
} else
1251-
return NULL;
1253+
return -1;
12521254
}
12531255

12541256
static int retry_bad_packed_offset(struct repository *r,
@@ -1558,16 +1560,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15581560

15591561
if (oi->delta_base_oid) {
15601562
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) {
15661566
type = OBJ_BAD;
15671567
goto out;
15681568
}
1569-
1570-
hashcpy(oi->delta_base_oid->hash, base);
15711569
} else
15721570
oidclr(oi->delta_base_oid);
15731571
}

0 commit comments

Comments
 (0)