mirror of
https://github.com/git/git.git
synced 2026-01-11 13:23:12 +09:00
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>
This commit is contained in:
parent
03d894e23c
commit
9c82ba6c32
21
packfile.c
21
packfile.c
@ -1587,6 +1587,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
|
||||
unsigned long size;
|
||||
off_t curpos = obj_offset;
|
||||
enum object_type type;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* 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,
|
||||
off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
|
||||
type, obj_offset);
|
||||
if (!base_offset) {
|
||||
type = OBJ_BAD;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
|
||||
if (*oi->sizep == 0) {
|
||||
type = OBJ_BAD;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
@ -1625,7 +1626,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
|
||||
if (offset_to_pack_pos(p, obj_offset, &pos) < 0) {
|
||||
error("could not find object at offset %"PRIuMAX" "
|
||||
"in pack %s", (uintmax_t)obj_offset, p->pack_name);
|
||||
type = OBJ_BAD;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -1639,7 +1640,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
|
||||
if (oi->typep)
|
||||
*oi->typep = ptot;
|
||||
if (ptot < 0) {
|
||||
type = OBJ_BAD;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -1649,7 +1650,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
|
||||
if (get_delta_base_oid(p, &w_curs, curpos,
|
||||
oi->delta_base_oid,
|
||||
type, obj_offset) < 0) {
|
||||
type = OBJ_BAD;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
@ -1672,9 +1673,11 @@ int packed_object_info(struct repository *r, struct packed_git *p,
|
||||
break;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
unuse_pack(&w_curs);
|
||||
return type;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *unpack_compressed_entry(struct packed_git *p,
|
||||
@ -2152,7 +2155,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
|
||||
unsigned flags UNUSED)
|
||||
{
|
||||
struct pack_entry e;
|
||||
int rtype;
|
||||
int ret;
|
||||
|
||||
if (!find_pack_entry(store->odb->repo, oid, &e))
|
||||
return 1;
|
||||
@ -2164,8 +2167,8 @@ int packfile_store_read_object_info(struct packfile_store *store,
|
||||
if (!oi)
|
||||
return 0;
|
||||
|
||||
rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi);
|
||||
if (rtype < 0) {
|
||||
ret = packed_object_info(store->odb->repo, e.p, e.offset, oi);
|
||||
if (ret < 0) {
|
||||
mark_bad_packed_object(e.p, oid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -378,6 +378,10 @@ void release_pack_memory(size_t);
|
||||
/* global flag to enable extra checks when accessing packed objects */
|
||||
extern int do_check_packed_object_crc;
|
||||
|
||||
/*
|
||||
* Look up the object info for a specific offset in the packfile.
|
||||
* Returns zero on success, a negative error code otherwise.
|
||||
*/
|
||||
int packed_object_info(struct repository *r,
|
||||
struct packed_git *pack,
|
||||
off_t offset, struct object_info *);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user