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>
Jeff King committed
Jul 12, 2013 at 02:37 UTC
23c339c0f262aad2515e48c33ec8f35d476d2ddc
1 file changed
+22
-27
sha1_file.c
+22
-27
@@ -1780,8 +1780,7 @@ unwind:
1780
}
1781
1782
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)
1784
{
1785
struct pack_window *w_curs = NULL;
1786
unsigned long size;
@@ -1794,7 +1793,7 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
1793
*/
1794
type = unpack_object_header(p, &w_curs, &curpos, &size);
1795
1797
- if (sizep) {
1796
+ if (oi->sizep) {
1797
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
1798
off_t tmp_pos = curpos;
1799
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,
1802
type = OBJ_BAD;
1803
goto out;
1804
}
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) {
1807
type = OBJ_BAD;
1808
goto out;
1809
}
1810
} else {
1812
- *sizep = size;
1811
+ *oi->sizep = size;
1812
}
1813
}
1814
1816
- if (disk_sizep) {
1815
+ if (oi->disk_sizep) {
1816
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;
1818
}
1819
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) {
1823
type = OBJ_BAD;
1824
goto out;
1825
}
@@ -2385,9 +2384,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
2384
}
2385
2386
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)
2388
{
2389
int status;
2390
unsigned long mapsize, size;
@@ -2399,12 +2396,12 @@ static int sha1_loose_object_info(const unsigned char *sha1,
2396
* If we don't care about type or size, then we don't
2397
* need to look inside the object at all.
2398
*/
2402
- if (!typep && !sizep) {
2403
- if (disk_sizep) {
2399
+ if (!oi->typep && !oi->sizep) {
2400
+ if (oi->disk_sizep) {
2401
struct stat st;
2402
if (stat_sha1_file(sha1, &st) < 0)
2403
return -1;
2407
- *disk_sizep = st.st_size;
2404
+ *oi->disk_sizep = st.st_size;
2405
}
2406
return 0;
2407
}
@@ -2412,19 +2409,19 @@ static int sha1_loose_object_info(const unsigned char *sha1,
2409
map = map_sha1_file(sha1, &mapsize);
2410
if (!map)
2411
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;
2414
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
2415
status = error("unable to unpack %s header",
2416
sha1_to_hex(sha1));
2417
else if ((status = parse_sha1_header(hdr, &size)) < 0)
2418
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;
2421
git_inflate_end(&stream);
2422
munmap(map, mapsize);
2426
- if (typep)
2427
- *typep = status;
2423
+ if (oi->typep)
2424
+ *oi->typep = status;
2425
return 0;
2426
}
2427
@@ -2449,8 +2446,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
2446
2447
if (!find_pack_entry(sha1, &e)) {
2448
/* 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)) {
2450
oi->whence = OI_LOOSE;
2451
return 0;
2452
}
@@ -2461,8 +2457,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
2457
return -1;
2458
}
2459
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);
2461
if (rtype < 0) {
2462
mark_bad_packed_object(e.p, sha1);
2463
return sha1_object_info_extended(sha1, oi);