Packbuilder contains its own zstream
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 9df9a01..c4ed4dc 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -130,6 +130,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
pb->nr_threads = 1; /* do not spawn any thread by default */
if (git_hash_ctx_init(&pb->ctx) < 0 ||
+ git_zstream_init(&pb->zstream) < 0 ||
git_repository_odb(&pb->odb, repo) < 0 ||
packbuilder_config(pb) < 0)
goto on_error;
@@ -284,7 +285,6 @@ static int write_object(
int (*write_cb)(void *buf, size_t size, void *cb_data),
void *cb_data)
{
- git_zstream zstream = GIT_ZSTREAM_INIT;
git_odb_object *obj = NULL;
git_otype type;
unsigned char hdr[10], *zbuf = NULL;
@@ -334,10 +334,9 @@ static int write_object(
zbuf = git__malloc(zbuf_len);
GITERR_CHECK_ALLOC(zbuf);
- if ((error = git_zstream_init(&zstream)) < 0)
- goto done;
+ git_zstream_reset(&pb->zstream);
- while ((written = git_zstream_deflate(zbuf, zbuf_len, &zstream, data, data_len)) > 0) {
+ while ((written = git_zstream_deflate(zbuf, zbuf_len, &pb->zstream, data, data_len)) > 0) {
if ((error = write_cb(zbuf, written, cb_data)) < 0 ||
(error = git_hash_update(&pb->ctx, zbuf, written)) < 0)
goto done;
@@ -364,7 +363,6 @@ static int write_object(
done:
git__free(zbuf);
- git_zstream_free(&zstream);
git_odb_object_free(obj);
return error;
}
@@ -1413,6 +1411,7 @@ void git_packbuilder_free(git_packbuilder *pb)
git__free(pb->object_list);
git_hash_ctx_cleanup(&pb->ctx);
+ git_zstream_free(&pb->zstream);
git__free(pb);
}
diff --git a/src/pack-objects.h b/src/pack-objects.h
index 0c94a5a..4647df7 100644
--- a/src/pack-objects.h
+++ b/src/pack-objects.h
@@ -14,6 +14,7 @@
#include "hash.h"
#include "oidmap.h"
#include "netops.h"
+#include "zstream.h"
#include "git2/oid.h"
#include "git2/pack.h"
@@ -54,6 +55,7 @@ struct git_packbuilder {
git_odb *odb; /* associated object database */
git_hash_ctx ctx;
+ git_zstream zstream;
uint32_t nr_objects,
nr_alloc,
diff --git a/src/zstream.c b/src/zstream.c
index e043dd3..7def044 100644
--- a/src/zstream.c
+++ b/src/zstream.c
@@ -52,6 +52,11 @@ ssize_t git_zstream_deflate(void *out, size_t out_len, git_zstream *zstream, con
return (out_len - zstream->avail_out);
}
+void git_zstream_reset(git_zstream *zstream)
+{
+ deflateReset(zstream);
+}
+
void git_zstream_free(git_zstream *zstream)
{
deflateEnd(zstream);
diff --git a/src/zstream.h b/src/zstream.h
index e6c8411..9672903 100644
--- a/src/zstream.h
+++ b/src/zstream.h
@@ -18,6 +18,7 @@
int git_zstream_init(git_zstream *zstream);
ssize_t git_zstream_deflate(void *out, size_t out_len, git_zstream *zstream, const void *in, size_t in_len);
+void git_zstream_reset(git_zstream *zstream);
void git_zstream_free(git_zstream *zstream);
int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len);