Skip to content

Commit 23c339c

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b08640 commit 23c339c

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

sha1_file.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,8 +1780,7 @@ static enum object_type packed_to_object_type(struct packed_git *p,
17801780
}
17811781

17821782
static int packed_object_info(struct packed_git *p, off_t obj_offset,
1783-
enum object_type *typep, unsigned long *sizep,
1784-
unsigned long *disk_sizep)
1783+
struct object_info *oi)
17851784
{
17861785
struct pack_window *w_curs = NULL;
17871786
unsigned long size;
@@ -1794,7 +1793,7 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
17941793
*/
17951794
type = unpack_object_header(p, &w_curs, &curpos, &size);
17961795

1797-
if (sizep) {
1796+
if (oi->sizep) {
17981797
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
17991798
off_t tmp_pos = curpos;
18001799
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,
18031802
type = OBJ_BAD;
18041803
goto out;
18051804
}
1806-
*sizep = get_size_from_delta(p, &w_curs, tmp_pos);
1807-
if (*sizep == 0) {
1805+
*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
1806+
if (*oi->sizep == 0) {
18081807
type = OBJ_BAD;
18091808
goto out;
18101809
}
18111810
} else {
1812-
*sizep = size;
1811+
*oi->sizep = size;
18131812
}
18141813
}
18151814

1816-
if (disk_sizep) {
1815+
if (oi->disk_sizep) {
18171816
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
1818-
*disk_sizep = revidx[1].offset - obj_offset;
1817+
*oi->disk_sizep = revidx[1].offset - obj_offset;
18191818
}
18201819

1821-
if (typep) {
1822-
*typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
1823-
if (*typep < 0) {
1820+
if (oi->typep) {
1821+
*oi->typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
1822+
if (*oi->typep < 0) {
18241823
type = OBJ_BAD;
18251824
goto out;
18261825
}
@@ -2385,9 +2384,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
23852384
}
23862385

23872386
static int sha1_loose_object_info(const unsigned char *sha1,
2388-
enum object_type *typep,
2389-
unsigned long *sizep,
2390-
unsigned long *disk_sizep)
2387+
struct object_info *oi)
23912388
{
23922389
int status;
23932390
unsigned long mapsize, size;
@@ -2399,32 +2396,32 @@ static int sha1_loose_object_info(const unsigned char *sha1,
23992396
* If we don't care about type or size, then we don't
24002397
* need to look inside the object at all.
24012398
*/
2402-
if (!typep && !sizep) {
2403-
if (disk_sizep) {
2399+
if (!oi->typep && !oi->sizep) {
2400+
if (oi->disk_sizep) {
24042401
struct stat st;
24052402
if (stat_sha1_file(sha1, &st) < 0)
24062403
return -1;
2407-
*disk_sizep = st.st_size;
2404+
*oi->disk_sizep = st.st_size;
24082405
}
24092406
return 0;
24102407
}
24112408

24122409
map = map_sha1_file(sha1, &mapsize);
24132410
if (!map)
24142411
return error("unable to find %s", sha1_to_hex(sha1));
2415-
if (disk_sizep)
2416-
*disk_sizep = mapsize;
2412+
if (oi->disk_sizep)
2413+
*oi->disk_sizep = mapsize;
24172414
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
24182415
status = error("unable to unpack %s header",
24192416
sha1_to_hex(sha1));
24202417
else if ((status = parse_sha1_header(hdr, &size)) < 0)
24212418
status = error("unable to parse %s header", sha1_to_hex(sha1));
2422-
else if (sizep)
2423-
*sizep = size;
2419+
else if (oi->sizep)
2420+
*oi->sizep = size;
24242421
git_inflate_end(&stream);
24252422
munmap(map, mapsize);
2426-
if (typep)
2427-
*typep = status;
2423+
if (oi->typep)
2424+
*oi->typep = status;
24282425
return 0;
24292426
}
24302427

@@ -2449,8 +2446,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
24492446

24502447
if (!find_pack_entry(sha1, &e)) {
24512448
/* Most likely it's a loose object. */
2452-
if (!sha1_loose_object_info(sha1, oi->typep,
2453-
oi->sizep, oi->disk_sizep)) {
2449+
if (!sha1_loose_object_info(sha1, oi)) {
24542450
oi->whence = OI_LOOSE;
24552451
return 0;
24562452
}
@@ -2461,8 +2457,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
24612457
return -1;
24622458
}
24632459

2464-
rtype = packed_object_info(e.p, e.offset, oi->typep, oi->sizep,
2465-
oi->disk_sizep);
2460+
rtype = packed_object_info(e.p, e.offset, oi);
24662461
if (rtype < 0) {
24672462
mark_bad_packed_object(e.p, sha1);
24682463
return sha1_object_info_extended(sha1, oi);

0 commit comments

Comments
 (0)