* [PATCH v2 2/2] index-pack: rationalize unpack_entry_data()
@ 2010-04-12 16:12 Nicolas Pitre
0 siblings, 0 replies; only message in thread
From: Nicolas Pitre @ 2010-04-12 16:12 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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>
---
builtin/index-pack.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 127e713..4308abb 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;
}
--
1.7.1.rc1.237.ge1730.dirty
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-04-12 16:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-12 16:12 [PATCH v2 2/2] index-pack: rationalize unpack_entry_data() Nicolas Pitre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox