summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2013-07-12 02:32:25 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-07-12 10:14:06 -0700
commit412916ee131cf8b0aaac96313ce8686aebe3a47a (patch)
tree797ed05d320bdee54e631d070bae7f118f71b679 /sha1_file.c
parentpacked_object_info: hoist delta type resolution to helper (diff)
downloadtgif-412916ee131cf8b0aaac96313ce8686aebe3a47a.tar.xz
packed_object_info: make type lookup optional
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 8fb10e451c..fa2809884b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1780,7 +1780,7 @@ unwind:
}
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;
@@ -1788,11 +1788,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;
@@ -1817,7 +1818,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);
@@ -2452,11 +2459,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 {