From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 5/7] packed_object_info: make type lookup optional
Date: Fri, 12 Jul 2013 02:32:25 -0400 [thread overview]
Message-ID: <20130712063225.GE15572@sigill.intra.peff.net> (raw)
In-Reply-To: <20130712061533.GA11297@sigill.intra.peff.net>
Currently, packed_object_info can save some work by not
calculating the size or disk_size of the object if the
caller is not interested. However, it always calculates the
true object type, whether the caller cares or not, and only
optionally returns the easy-to-get "representation type".
Let's swap these types. The function will now return the
representation type (or OBJ_BAD on failure), and will only
optionally fill in the true type.
There should be no behavior change yet, as the only caller,
sha1_object_info_extended, will always feed it a type
pointer.
Signed-off-by: Jeff King <peff@peff.net>
---
sha1_file.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 6f4aff3..2a1e230 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1783,7 +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,
- unsigned long *sizep, int *rtype,
+ enum object_type *typep, unsigned long *sizep,
unsigned long *disk_sizep)
{
struct pack_window *w_curs = NULL;
@@ -1791,11 +1791,12 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
off_t curpos = obj_offset;
enum object_type type;
+ /*
+ * We always get the representation type, but only convert it to
+ * a "real" type later if the caller is interested.
+ */
type = unpack_object_header(p, &w_curs, &curpos, &size);
- if (rtype)
- *rtype = type; /* representation type */
-
if (sizep) {
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) {
off_t tmp_pos = curpos;
@@ -1820,7 +1821,13 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset,
*disk_sizep = revidx[1].offset - obj_offset;
}
- type = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
+ if (typep) {
+ *typep = packed_to_object_type(p, obj_offset, type, &w_curs, curpos);
+ if (*typep < 0) {
+ type = OBJ_BAD;
+ goto out;
+ }
+ }
out:
unuse_pack(&w_curs);
@@ -2471,11 +2478,11 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
return -1;
}
- type = packed_object_info(e.p, e.offset, oi->sizep, &rtype,
- oi->disk_sizep);
- if (type < 0) {
+ rtype = packed_object_info(e.p, e.offset, &type, oi->sizep,
+ oi->disk_sizep);
+ if (rtype < 0) {
mark_bad_packed_object(e.p, sha1);
- type = sha1_object_info_extended(sha1, oi);
+ return sha1_object_info_extended(sha1, oi);
} else if (in_delta_base_cache(e.p, e.offset)) {
oi->whence = OI_DBCACHED;
} else {
--
1.8.3.rc3.24.gec82cb9
next prev parent reply other threads:[~2013-07-12 6:32 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 ` Jeff King [this message]
2013-07-12 6:34 ` [PATCH 6/7] sha1_object_info_extended: make type calculation optional Jeff King
2013-07-12 6:37 ` [PATCH 7/7] sha1_object_info_extended: pass object_info to helpers Jeff King
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=20130712063225.GE15572@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).