pack: move unpack_object_header_buffer()

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 32b42e152fcc453273fadb5a7d639e4e9b506783
4 files changed +27 -26
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 unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
1666 extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
1667 extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
1668
packfile.c
+25
@@ -884,3 +884,28 @@ void reprepare_packed_git(void)
884 prepare_packed_git_run_once = 0;
885 prepare_packed_git();
886 }
887 +
888 +unsigned long unpack_object_header_buffer(const unsigned char *buf,
889 + unsigned long len, enum object_type *type, unsigned long *sizep)
890 +{
891 + unsigned shift;
892 + unsigned long size, c;
893 + unsigned long used = 0;
894 +
895 + c = buf[used++];
896 + *type = (c >> 4) & 7;
897 + size = c & 15;
898 + shift = 4;
899 + while (c & 0x80) {
900 + if (len <= used || bitsizeof(long) <= shift) {
901 + error("bad object header");
902 + size = used = 0;
903 + break;
904 + }
905 + c = buf[used++];
906 + size += (c & 0x7f) << shift;
907 + shift += 7;
908 + }
909 + *sizep = size;
910 + return used;
911 +}
packfile.h
+2
@@ -62,6 +62,8 @@ extern void close_all_packs(void);
62 extern void unuse_pack(struct pack_window **);
63 extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
64
65 +extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
66 +
67 extern void release_pack_memory(size_t);
68
69 extern int open_packed_git(struct packed_git *p);
sha1_file.c
-25
@@ -915,31 +915,6 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
915 return map_sha1_file_1(NULL, sha1, size);
916 }
917
918 -unsigned long unpack_object_header_buffer(const unsigned char *buf,
919 - unsigned long len, enum object_type *type, unsigned long *sizep)
920 -{
921 - unsigned shift;
922 - unsigned long size, c;
923 - unsigned long used = 0;
924 -
925 - c = buf[used++];
926 - *type = (c >> 4) & 7;
927 - size = c & 15;
928 - shift = 4;
929 - while (c & 0x80) {
930 - if (len <= used || bitsizeof(long) <= shift) {
931 - error("bad object header");
932 - size = used = 0;
933 - break;
934 - }
935 - c = buf[used++];
936 - size += (c & 0x7f) << shift;
937 - shift += 7;
938 - }
939 - *sizep = size;
940 - return used;
941 -}
942 -
918 static int unpack_sha1_short_header(git_zstream *stream,
919 unsigned char *map, unsigned long mapsize,
920 void *buffer, unsigned long bufsiz)