pack: move get_size_from_delta()

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 7b3aa75df7db72a283a11b9ce41658b89576db2b
4 files changed +41 -40
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 get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
1666 extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *);
1667
1668 /*
packfile.c
+40
@@ -4,6 +4,7 @@
4 #include "dir.h"
5 #include "mergesort.h"
6 #include "packfile.h"
7 +#include "delta.h"
8
9 char *odb_pack_name(struct strbuf *buf,
10 const unsigned char *sha1,
@@ -909,3 +910,42 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
910 *sizep = size;
911 return used;
912 }
913 +
914 +unsigned long get_size_from_delta(struct packed_git *p,
915 + struct pack_window **w_curs,
916 + off_t curpos)
917 +{
918 + const unsigned char *data;
919 + unsigned char delta_head[20], *in;
920 + git_zstream stream;
921 + int st;
922 +
923 + memset(&stream, 0, sizeof(stream));
924 + stream.next_out = delta_head;
925 + stream.avail_out = sizeof(delta_head);
926 +
927 + git_inflate_init(&stream);
928 + do {
929 + in = use_pack(p, w_curs, curpos, &stream.avail_in);
930 + stream.next_in = in;
931 + st = git_inflate(&stream, Z_FINISH);
932 + curpos += stream.next_in - in;
933 + } while ((st == Z_OK || st == Z_BUF_ERROR) &&
934 + stream.total_out < sizeof(delta_head));
935 + git_inflate_end(&stream);
936 + if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
937 + error("delta data unpack-initial failed");
938 + return 0;
939 + }
940 +
941 + /* Examine the initial part of the delta to figure out
942 + * the result size.
943 + */
944 + data = delta_head;
945 +
946 + /* ignore base size */
947 + get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
948 +
949 + /* Read the result size */
950 + return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
951 +}
packfile.h
+1
@@ -63,6 +63,7 @@ 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 +extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
67
68 extern void release_pack_memory(size_t);
69
sha1_file.c
-39
@@ -1101,45 +1101,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
1101 return parse_sha1_header_extended(hdr, &oi, 0);
1102 }
1103
1104 -unsigned long get_size_from_delta(struct packed_git *p,
1105 - struct pack_window **w_curs,
1106 - off_t curpos)
1107 -{
1108 - const unsigned char *data;
1109 - unsigned char delta_head[20], *in;
1110 - git_zstream stream;
1111 - int st;
1112 -
1113 - memset(&stream, 0, sizeof(stream));
1114 - stream.next_out = delta_head;
1115 - stream.avail_out = sizeof(delta_head);
1116 -
1117 - git_inflate_init(&stream);
1118 - do {
1119 - in = use_pack(p, w_curs, curpos, &stream.avail_in);
1120 - stream.next_in = in;
1121 - st = git_inflate(&stream, Z_FINISH);
1122 - curpos += stream.next_in - in;
1123 - } while ((st == Z_OK || st == Z_BUF_ERROR) &&
1124 - stream.total_out < sizeof(delta_head));
1125 - git_inflate_end(&stream);
1126 - if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
1127 - error("delta data unpack-initial failed");
1128 - return 0;
1129 - }
1130 -
1131 - /* Examine the initial part of the delta to figure out
1132 - * the result size.
1133 - */
1134 - data = delta_head;
1135 -
1136 - /* ignore base size */
1137 - get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1138 -
1139 - /* Read the result size */
1140 - return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1141 -}
1142 -
1104 static off_t get_delta_base(struct packed_git *p,
1105 struct pack_window **w_curs,
1106 off_t *curpos,