diff --git a/src/pack-objects.c b/src/pack-objects.c index 9df9a015e..c4ed4dce3 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 0c94a5a7a..4647df75a 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 e043dd3a9..7def0440b 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 e6c841120..9672903c0 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);