summaryrefslogtreecommitdiff
path: root/builtin-index-pack.c
diff options
context:
space:
mode:
authorLibravatar Nicolas Pitre <nico@fluxnic.net>2010-04-12 12:12:06 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-04-12 09:51:42 -0700
commit7ce4721ad8c65ab4d9a9e94176001f12bb4b5218 (patch)
treed3ffe9a9e039ec81d4da6a34a8548d683ea4493b /builtin-index-pack.c
parentindex-pack: smarter memory usage when resolving deltas (diff)
downloadtgif-7ce4721ad8c65ab4d9a9e94176001f12bb4b5218.tar.xz
index-pack: rationalize unpack_entry_data()
Rework the loop to remove duplicated calls to use() and fill(), and to make the code easier to read. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-index-pack.c')
-rw-r--r--builtin-index-pack.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/builtin-index-pack.c b/builtin-index-pack.c
index 127e713dde..4308abb60e 100644
--- a/builtin-index-pack.c
+++ b/builtin-index-pack.c
@@ -266,26 +266,23 @@ static void unlink_base_data(struct base_data *c)
static void *unpack_entry_data(unsigned long offset, unsigned long size)
{
+ int status;
z_stream stream;
void *buf = xmalloc(size);
memset(&stream, 0, sizeof(stream));
+ git_inflate_init(&stream);
stream.next_out = buf;
stream.avail_out = size;
- stream.next_in = fill(1);
- stream.avail_in = input_len;
- git_inflate_init(&stream);
- for (;;) {
- int ret = git_inflate(&stream, 0);
- use(input_len - stream.avail_in);
- if (stream.total_out == size && ret == Z_STREAM_END)
- break;
- if (ret != Z_OK)
- bad_object(offset, "inflate returned %d", ret);
+ do {
stream.next_in = fill(1);
stream.avail_in = input_len;
- }
+ status = git_inflate(&stream, 0);
+ use(input_len - stream.avail_in);
+ } while (status == Z_OK);
+ if (stream.total_out != size || status != Z_STREAM_END)
+ bad_object(offset, "inflate returned %d", status);
git_inflate_end(&stream);
return buf;
}