From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 7/7] sha1_object_info_extended: pass object_info to helpers
Date: Fri, 12 Jul 2013 02:37:53 -0400 [thread overview]
Message-ID: <20130712063752.GG15572@sigill.intra.peff.net> (raw)
In-Reply-To: <20130712061533.GA11297@sigill.intra.peff.net>
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>
---
This one is an optional cleanup. The diff is quite noisy due to all of
the s/foo/oi->foo/, so it is arguable whether the result is nicer or
not. It would make later additions to object_info nicer, but I do not
plan to add any more.
It _would_ have been a nice cleanup to do at the beginning of the series
(and further diffs would not have to add extra parameters to the
function calls), but that would make the incremental "learn to do type
optionally" patches quite awkward.
So I am on the fence over this one, and do not mind too much if it gets
dropped.
sha1_file.c | 49 ++++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 52f7a1e..563f521 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1783,8 +1783,7 @@ 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,
- unsigned long *disk_sizep)
+ struct object_info *oi)
{
struct pack_window *w_curs = NULL;
unsigned long size;
@@ -1797,7 +1796,7 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
*/
type = unpack_object_header(p, &w_curs, &curpos, &size);
- if (sizep) {
+ if (oi->sizep) {
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
off_t tmp_pos = curpos;
off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
@@ -1806,24 +1805,24 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
type = OBJ_BAD;
goto out;
}
- *sizep = get_size_from_delta(p, &w_curs, tmp_pos);
- if (*sizep == 0) {
+ *oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
+ if (*oi->sizep == 0) {
type = OBJ_BAD;
goto out;
}
} else {
- *sizep = size;
+ *oi->sizep = size;
}
}
- if (disk_sizep) {
+ if (oi->disk_sizep) {
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) {
- *typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
- if (*typep < 0) {
+ if (oi->typep) {
+ *oi->typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
+ if (*oi->typep < 0) {
type = OBJ_BAD;
goto out;
}
@@ -2404,9 +2403,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
}
static int sha1_loose_object_info(const unsigned char *sha1,
- enum object_type *typep,
- unsigned long *sizep,
- unsigned long *disk_sizep)
+ struct object_info *oi)
{
int status;
unsigned long mapsize, size;
@@ -2418,12 +2415,12 @@ static int sha1_loose_object_info(const unsigned char *sha1,
* If we don't care about type or size, then we don't
* need to look inside the object at all.
*/
- if (!typep && !sizep) {
- if (disk_sizep) {
+ if (!oi->typep && !oi->sizep) {
+ if (oi->disk_sizep) {
struct stat st;
if (stat_sha1_file(sha1, &st) < 0)
return -1;
- *disk_sizep = st.st_size;
+ *oi->disk_sizep = st.st_size;
}
return 0;
}
@@ -2431,19 +2428,19 @@ static int sha1_loose_object_info(const unsigned char *sha1,
map = map_sha1_file(sha1, &mapsize);
if (!map)
return -1;
- if (disk_sizep)
- *disk_sizep = mapsize;
+ if (oi->disk_sizep)
+ *oi->disk_sizep = mapsize;
if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
status = error("unable to unpack %s header",
sha1_to_hex(sha1));
else if ((status = parse_sha1_header(hdr, &size)) < 0)
status = error("unable to parse %s header", sha1_to_hex(sha1));
- else if (sizep)
- *sizep = size;
+ else if (oi->sizep)
+ *oi->sizep = size;
git_inflate_end(&stream);
munmap(map, mapsize);
- if (typep)
- *typep = status;
+ if (oi->typep)
+ *oi->typep = status;
return 0;
}
@@ -2468,8 +2465,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
if (!find_pack_entry(sha1, &e)) {
/* Most likely it's a loose object. */
- if (!sha1_loose_object_info(sha1, oi->typep,
- oi->sizep, oi->disk_sizep)) {
+ if (!sha1_loose_object_info(sha1, oi)) {
oi->whence = OI_LOOSE;
return 0;
}
@@ -2480,8 +2476,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
return -1;
}
- rtype = packed_object_info(e.p, e.offset, oi->typep, oi->sizep,
- oi->disk_sizep);
+ rtype = packed_object_info(e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, sha1);
return sha1_object_info_extended(sha1, oi);
--
1.8.3.rc3.24.gec82cb9
next prev parent reply other threads:[~2013-07-12 6:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 6:15 [PATCH 0/7] cat-file --batch-check performance improvements Jeff King
2013-07-12 6:20 ` [PATCH 1/7] cat-file: disable object/refname ambiguity check for batch mode Jeff King
2013-07-12 8:47 ` Michael Haggerty
2013-07-12 9:22 ` Jeff King
2013-07-12 10:30 ` Michael Haggerty
2013-07-15 4:23 ` Jeff King
2013-07-15 3:45 ` Junio C Hamano
2013-07-15 4:17 ` Jeff King
2013-07-12 6:21 ` [PATCH 2/7] sha1_object_info_extended: rename "status" to "type" Jeff King
2013-07-12 6:30 ` [PATCH 3/7] sha1_loose_object_info: make type lookup optional Jeff King
2013-07-12 6:31 ` [PATCH 4/7] packed_object_info: hoist delta type resolution to helper Jeff King
2013-07-12 6:32 ` [PATCH 5/7] packed_object_info: make type lookup optional Jeff King
2013-07-12 6:34 ` [PATCH 6/7] sha1_object_info_extended: make type calculation optional Jeff King
2013-07-12 6:37 ` Jeff King [this message]
2013-07-12 17:23 ` [PATCH 0/7] cat-file --batch-check performance improvements Junio C Hamano
2013-07-12 20:12 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130712063752.GG15572@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).