Commit 52a8a130 by Edward Thomson

Packbuilder contains its own zstream

parent 0ade2f7a
......@@ -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);
}
......@@ -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,
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment