Skip to content

Commit 8908c30

Browse files
pks-tgitster
authored andcommitted
packfile: disentangle return value of packed_object_info()
The `packed_object_info()` function returns the type of the packed object. While we use an `enum object_type` to store the return value, this type is not to be confused with the actual object type. It _may_ contain the object type, but it may just as well encode that the given packed object is stored as a delta. We have removed the only caller that relied on this returned object type in the preceding commit, so let's simplify semantics and return either 0 on success or a negative error code otherwise. This unblocks a small optimization where we can skip reading the object type altogether. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 57c168d commit 8908c30

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

packfile.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15871587
unsigned long size;
15881588
off_t curpos = obj_offset;
15891589
enum object_type type;
1590+
int ret;
15901591

15911592
/*
15921593
* We always get the representation type, but only convert it to
@@ -1607,12 +1608,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16071608
off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
16081609
type, obj_offset);
16091610
if (!base_offset) {
1610-
type = OBJ_BAD;
1611+
ret = -1;
16111612
goto out;
16121613
}
16131614
*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
16141615
if (*oi->sizep == 0) {
1615-
type = OBJ_BAD;
1616+
ret = -1;
16161617
goto out;
16171618
}
16181619
} else {
@@ -1625,7 +1626,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16251626
if (offset_to_pack_pos(p, obj_offset, &pos) < 0) {
16261627
error("could not find object at offset %"PRIuMAX" "
16271628
"in pack %s", (uintmax_t)obj_offset, p->pack_name);
1628-
type = OBJ_BAD;
1629+
ret = -1;
16291630
goto out;
16301631
}
16311632

@@ -1639,7 +1640,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16391640
if (oi->typep)
16401641
*oi->typep = ptot;
16411642
if (ptot < 0) {
1642-
type = OBJ_BAD;
1643+
ret = -1;
16431644
goto out;
16441645
}
16451646
}
@@ -1649,7 +1650,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16491650
if (get_delta_base_oid(p, &w_curs, curpos,
16501651
oi->delta_base_oid,
16511652
type, obj_offset) < 0) {
1652-
type = OBJ_BAD;
1653+
ret = -1;
16531654
goto out;
16541655
}
16551656
} else
@@ -1672,9 +1673,11 @@ int packed_object_info(struct repository *r, struct packed_git *p,
16721673
break;
16731674
}
16741675

1676+
ret = 0;
1677+
16751678
out:
16761679
unuse_pack(&w_curs);
1677-
return type;
1680+
return ret;
16781681
}
16791682

16801683
static void *unpack_compressed_entry(struct packed_git *p,
@@ -2152,7 +2155,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
21522155
unsigned flags UNUSED)
21532156
{
21542157
struct pack_entry e;
2155-
int rtype;
2158+
int ret;
21562159

21572160
if (!find_pack_entry(store->odb->repo, oid, &e))
21582161
return 1;
@@ -2164,8 +2167,8 @@ int packfile_store_read_object_info(struct packfile_store *store,
21642167
if (!oi)
21652168
return 0;
21662169

2167-
rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi);
2168-
if (rtype < 0) {
2170+
ret = packed_object_info(store->odb->repo, e.p, e.offset, oi);
2171+
if (ret < 0) {
21692172
mark_bad_packed_object(e.p, oid);
21702173
return -1;
21712174
}

packfile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ void release_pack_memory(size_t);
378378
/* global flag to enable extra checks when accessing packed objects */
379379
extern int do_check_packed_object_crc;
380380

381+
/*
382+
* Look up the object info for a specific offset in the packfile.
383+
* Returns zero on success, a negative error code otherwise.
384+
*/
381385
int packed_object_info(struct repository *r,
382386
struct packed_git *pack,
383387
off_t offset, struct object_info *);

0 commit comments

Comments
 (0)