sha1_object_info_extended: pass object_info to helpers
We take in a "struct object_info" which contains pointers to storage for items the caller cares about. But then rather than pass the whole object to the low-level loose/packed helper functions, we pass the individual pointers. Let's pass the whole struct instead, which will make adding more items later easier. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5b0864070e
commit
23c339c0f2
49
sha1_file.c
49
sha1_file.c
@ -1780,8 +1780,7 @@ unwind:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int packed_object_info(struct packed_git *p, off_t obj_offset,
|
static int packed_object_info(struct packed_git *p, off_t obj_offset,
|
||||||
enum object_type *typep, unsigned long *sizep,
|
struct object_info *oi)
|
||||||
unsigned long *disk_sizep)
|
|
||||||
{
|
{
|
||||||
struct pack_window *w_curs = NULL;
|
struct pack_window *w_curs = NULL;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
@ -1794,7 +1793,7 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
|
|||||||
*/
|
*/
|
||||||
type = unpack_object_header(p, &w_curs, &curpos, &size);
|
type = unpack_object_header(p, &w_curs, &curpos, &size);
|
||||||
|
|
||||||
if (sizep) {
|
if (oi->sizep) {
|
||||||
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
|
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
|
||||||
off_t tmp_pos = curpos;
|
off_t tmp_pos = curpos;
|
||||||
off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
|
off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
|
||||||
@ -1803,24 +1802,24 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
|
|||||||
type = OBJ_BAD;
|
type = OBJ_BAD;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
*sizep = get_size_from_delta(p, &w_curs, tmp_pos);
|
*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
|
||||||
if (*sizep == 0) {
|
if (*oi->sizep == 0) {
|
||||||
type = OBJ_BAD;
|
type = OBJ_BAD;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*sizep = size;
|
*oi->sizep = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disk_sizep) {
|
if (oi->disk_sizep) {
|
||||||
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
|
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
|
||||||
*disk_sizep = revidx[1].offset - obj_offset;
|
*oi->disk_sizep = revidx[1].offset - obj_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typep) {
|
if (oi->typep) {
|
||||||
*typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
|
*oi->typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
|
||||||
if (*typep < 0) {
|
if (*oi->typep < 0) {
|
||||||
type = OBJ_BAD;
|
type = OBJ_BAD;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -2385,9 +2384,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int sha1_loose_object_info(const unsigned char *sha1,
|
static int sha1_loose_object_info(const unsigned char *sha1,
|
||||||
enum object_type *typep,
|
struct object_info *oi)
|
||||||
unsigned long *sizep,
|
|
||||||
unsigned long *disk_sizep)
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
unsigned long mapsize, size;
|
unsigned long mapsize, size;
|
||||||
@ -2399,12 +2396,12 @@ static int sha1_loose_object_info(const unsigned char *sha1,
|
|||||||
* If we don't care about type or size, then we don't
|
* If we don't care about type or size, then we don't
|
||||||
* need to look inside the object at all.
|
* need to look inside the object at all.
|
||||||
*/
|
*/
|
||||||
if (!typep && !sizep) {
|
if (!oi->typep && !oi->sizep) {
|
||||||
if (disk_sizep) {
|
if (oi->disk_sizep) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat_sha1_file(sha1, &st) < 0)
|
if (stat_sha1_file(sha1, &st) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
*disk_sizep = st.st_size;
|
*oi->disk_sizep = st.st_size;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2412,19 +2409,19 @@ static int sha1_loose_object_info(const unsigned char *sha1,
|
|||||||
map = map_sha1_file(sha1, &mapsize);
|
map = map_sha1_file(sha1, &mapsize);
|
||||||
if (!map)
|
if (!map)
|
||||||
return error("unable to find %s", sha1_to_hex(sha1));
|
return error("unable to find %s", sha1_to_hex(sha1));
|
||||||
if (disk_sizep)
|
if (oi->disk_sizep)
|
||||||
*disk_sizep = mapsize;
|
*oi->disk_sizep = mapsize;
|
||||||
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
|
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
|
||||||
status = error("unable to unpack %s header",
|
status = error("unable to unpack %s header",
|
||||||
sha1_to_hex(sha1));
|
sha1_to_hex(sha1));
|
||||||
else if ((status = parse_sha1_header(hdr, &size)) < 0)
|
else if ((status = parse_sha1_header(hdr, &size)) < 0)
|
||||||
status = error("unable to parse %s header", sha1_to_hex(sha1));
|
status = error("unable to parse %s header", sha1_to_hex(sha1));
|
||||||
else if (sizep)
|
else if (oi->sizep)
|
||||||
*sizep = size;
|
*oi->sizep = size;
|
||||||
git_inflate_end(&stream);
|
git_inflate_end(&stream);
|
||||||
munmap(map, mapsize);
|
munmap(map, mapsize);
|
||||||
if (typep)
|
if (oi->typep)
|
||||||
*typep = status;
|
*oi->typep = status;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2449,8 +2446,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
|
|||||||
|
|
||||||
if (!find_pack_entry(sha1, &e)) {
|
if (!find_pack_entry(sha1, &e)) {
|
||||||
/* Most likely it's a loose object. */
|
/* Most likely it's a loose object. */
|
||||||
if (!sha1_loose_object_info(sha1, oi->typep,
|
if (!sha1_loose_object_info(sha1, oi)) {
|
||||||
oi->sizep, oi->disk_sizep)) {
|
|
||||||
oi->whence = OI_LOOSE;
|
oi->whence = OI_LOOSE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2461,8 +2457,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtype = packed_object_info(e.p, e.offset, oi->typep, oi->sizep,
|
rtype = packed_object_info(e.p, e.offset, oi);
|
||||||
oi->disk_sizep);
|
|
||||||
if (rtype < 0) {
|
if (rtype < 0) {
|
||||||
mark_bad_packed_object(e.p, sha1);
|
mark_bad_packed_object(e.p, sha1);
|
||||||
return sha1_object_info_extended(sha1, oi);
|
return sha1_object_info_extended(sha1, oi);
|
||||||
|
Reference in New Issue
Block a user