summaryrefslogtreecommitdiff
path: root/packfile.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-08-18 15:20:29 -0700
committerJunio C Hamano <gitster@pobox.com>2017-08-23 15:12:07 -0700
commit3588dd6e994b38b02c2f60544fe2f69ce5fdf927 (patch)
tree0a3297c84872f577fb8bf9351811c249f0dff682 /packfile.c
parent7b3aa75df7db72a283a11b9ce41658b89576db2b (diff)
downloadgit-3588dd6e994b38b02c2f60544fe2f69ce5fdf927.tar.gz
pack: move unpack_object_header()
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/packfile.c b/packfile.c
index 9e0bbf5a0e..d4a78b1ac9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -949,3 +949,29 @@ unsigned long get_size_from_delta(struct packed_git *p,
/* Read the result size */
return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
}
+
+int unpack_object_header(struct packed_git *p,
+ struct pack_window **w_curs,
+ off_t *curpos,
+ unsigned long *sizep)
+{
+ unsigned char *base;
+ unsigned long left;
+ unsigned long used;
+ enum object_type type;
+
+ /* use_pack() assures us we have [base, base + 20) available
+ * as a range that we can look at. (Its actually the hash
+ * size that is assured.) With our object header encoding
+ * the maximum deflated object size is 2^137, which is just
+ * insane, so we know won't exceed what we have been given.
+ */
+ base = use_pack(p, w_curs, *curpos, &left);
+ used = unpack_object_header_buffer(base, left, &type, sizep);
+ if (!used) {
+ type = OBJ_BAD;
+ } else
+ *curpos += used;
+
+ return type;
+}