pack: move unpack_object_header()
[gitweb.git] / packfile.c
index 9e0bbf5a0e977f2e2c5eccb3f2063849f82d8c13..d4a78b1ac907d47bcab3e85ac568a6956b6a1280 100644 (file)
@@ -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;
+}