diff options
author | Russell Belfer <rb@github.com> | 2014-01-29 15:02:35 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-01-30 09:59:59 -0800 |
commit | d9b04d78a396f771eada206b726ad6e8259a19b8 (patch) | |
tree | 3af4cc0b2bc757b848de1947ce9344474168a82d /src/pack-objects.c | |
parent | e9d5e5f3d41846b5f3be1bfb6a5cb1e501f428c8 (diff) | |
download | libgit2-d9b04d78a396f771eada206b726ad6e8259a19b8.tar.gz |
Reorganize zstream API and fix wrap problems
There were some confusing issues mixing up the number of bytes
written to the zstream output buffer with the number of bytes
consumed from the zstream input. This reorganizes the zstream
API and makes it easier to deflate an arbitrarily large input
while still using a fixed size output.
Diffstat (limited to 'src/pack-objects.c')
-rw-r--r-- | src/pack-objects.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/pack-objects.c b/src/pack-objects.c index 8475f64f2..8b65ac26a 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -291,7 +291,6 @@ static int write_object( void *delta_data = NULL; void *data; size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len; - ssize_t written; int error; if (po->delta) { @@ -337,19 +336,15 @@ static int write_object( GITERR_CHECK_ALLOC(zbuf); git_zstream_reset(&pb->zstream); + git_zstream_set_input(&pb->zstream, data, data_len); - 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) + while (!git_zstream_done(&pb->zstream)) { + if ((error = git_zstream_get_output(zbuf, &zbuf_len, &pb->zstream)) < 0 || + (error = write_cb(zbuf, zbuf_len, cb_data)) < 0 || + (error = git_hash_update(&pb->ctx, zbuf, zbuf_len)) < 0) goto done; - data = (char *)data + written; - data_len -= written; - } - - if (written < 0) { - error = (int)written; - goto done; + zbuf_len = COMPRESS_BUFLEN; /* reuse buffer */ } if (po->delta) |