Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-08-19 01:20:28 +0300
committerJunio C Hamano <gitster@pobox.com>2017-08-24 01:12:07 +0300
commit7b3aa75df7db72a283a11b9ce41658b89576db2b (patch)
tree21f4a19de17bc52fbf779ca4227a2462af3fd4ea /packfile.c
parent32b42e152fcc453273fadb5a7d639e4e9b506783 (diff)
pack: move get_size_from_delta()
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.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/packfile.c b/packfile.c
index 1116942043..9e0bbf5a0e 100644
--- a/packfile.c
+++ b/packfile.c
@@ -4,6 +4,7 @@
#include "dir.h"
#include "mergesort.h"
#include "packfile.h"
+#include "delta.h"
char *odb_pack_name(struct strbuf *buf,
const unsigned char *sha1,
@@ -909,3 +910,42 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
*sizep = size;
return used;
}
+
+unsigned long get_size_from_delta(struct packed_git *p,
+ struct pack_window **w_curs,
+ off_t curpos)
+{
+ const unsigned char *data;
+ unsigned char delta_head[20], *in;
+ git_zstream stream;
+ int st;
+
+ memset(&stream, 0, sizeof(stream));
+ stream.next_out = delta_head;
+ stream.avail_out = sizeof(delta_head);
+
+ git_inflate_init(&stream);
+ do {
+ in = use_pack(p, w_curs, curpos, &stream.avail_in);
+ stream.next_in = in;
+ st = git_inflate(&stream, Z_FINISH);
+ curpos += stream.next_in - in;
+ } while ((st == Z_OK || st == Z_BUF_ERROR) &&
+ stream.total_out < sizeof(delta_head));
+ git_inflate_end(&stream);
+ if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) {
+ error("delta data unpack-initial failed");
+ return 0;
+ }
+
+ /* Examine the initial part of the delta to figure out
+ * the result size.
+ */
+ data = delta_head;
+
+ /* ignore base size */
+ get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
+
+ /* Read the result size */
+ return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
+}