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>
Nicolas Pitre committed
Apr 12, 2010 at 12:12 UTC
7ce4721ad8c65ab4d9a9e94176001f12bb4b5218
1 file changed
+8
-11
builtin-index-pack.c
+8
-11
@@ -266,26 +266,23 @@ static void unlink_base_data(struct base_data *c)
266
267
static void *unpack_entry_data(unsigned long offset, unsigned long size)
268
{
269
+ int status;
270
z_stream stream;
271
void *buf = xmalloc(size);
272
273
memset(&stream, 0, sizeof(stream));
274
+ git_inflate_init(&stream);
275
stream.next_out = buf;
276
stream.avail_out = size;
275
- stream.next_in = fill(1);
276
- stream.avail_in = input_len;
277
- git_inflate_init(&stream);
277
279
- for (;;) {
280
- int ret = git_inflate(&stream, 0);
281
- use(input_len - stream.avail_in);
282
- if (stream.total_out == size && ret == Z_STREAM_END)
283
- break;
284
- if (ret != Z_OK)
285
- bad_object(offset, "inflate returned %d", ret);
278
+ do {
279
stream.next_in = fill(1);
280
stream.avail_in = input_len;
288
- }
281
+ status = git_inflate(&stream, 0);
282
+ use(input_len - stream.avail_in);
283
+ } while (status == Z_OK);
284
+ if (stream.total_out != size || status != Z_STREAM_END)
285
+ bad_object(offset, "inflate returned %d", status);
286
git_inflate_end(&stream);
287
return buf;
288
}