pack: move unpack_object_header()

Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Aug 18, 2017 at 15:20 UTC 3588dd6e994b38b02c2f60544fe2f69ce5fdf927
4 files changed +27 -27
cache.h
-1
@@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *)
1663
1664 extern int is_pack_valid(struct packed_git *);
1665 extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
1666 -extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
1666
1667 /*
1668 * Iterate over the files in the loose-object parts of the object
packfile.c
+26
@@ -949,3 +949,29 @@ unsigned long get_size_from_delta(struct packed_git *p,
949 /* Read the result size */
950 return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
951 }
952 +
953 +int unpack_object_header(struct packed_git *p,
954 + struct pack_window **w_curs,
955 + off_t *curpos,
956 + unsigned long *sizep)
957 +{
958 + unsigned char *base;
959 + unsigned long left;
960 + unsigned long used;
961 + enum object_type type;
962 +
963 + /* use_pack() assures us we have [base, base + 20) available
964 + * as a range that we can look at. (Its actually the hash
965 + * size that is assured.) With our object header encoding
966 + * the maximum deflated object size is 2^137, which is just
967 + * insane, so we know won't exceed what we have been given.
968 + */
969 + base = use_pack(p, w_curs, *curpos, &left);
970 + used = unpack_object_header_buffer(base, left, &type, sizep);
971 + if (!used) {
972 + type = OBJ_BAD;
973 + } else
974 + *curpos += used;
975 +
976 + return type;
977 +}
packfile.h
+1
@@ -64,6 +64,7 @@ extern struct packed_git *add_packed_git(const char *path, size_t path_len, int
64
65 extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
66 extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
67 +extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
68
69 extern void release_pack_memory(size_t);
70
sha1_file.c
-26
@@ -1172,32 +1172,6 @@ static const unsigned char *get_delta_base_sha1(struct packed_git *p,
1172 return NULL;
1173 }
1174
1175 -int unpack_object_header(struct packed_git *p,
1176 - struct pack_window **w_curs,
1177 - off_t *curpos,
1178 - unsigned long *sizep)
1179 -{
1180 - unsigned char *base;
1181 - unsigned long left;
1182 - unsigned long used;
1183 - enum object_type type;
1184 -
1185 - /* use_pack() assures us we have [base, base + 20) available
1186 - * as a range that we can look at. (Its actually the hash
1187 - * size that is assured.) With our object header encoding
1188 - * the maximum deflated object size is 2^137, which is just
1189 - * insane, so we know won't exceed what we have been given.
1190 - */
1191 - base = use_pack(p, w_curs, *curpos, &left);
1192 - used = unpack_object_header_buffer(base, left, &type, sizep);
1193 - if (!used) {
1194 - type = OBJ_BAD;
1195 - } else
1196 - *curpos += used;
1197 -
1198 - return type;
1199 -}
1200 -
1175 static int retry_bad_packed_offset(struct packed_git *p, off_t obj_offset)
1176 {
1177 int type;