Skip to content

Commit 7ce4721

Browse files
npitregitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 776ea37 commit 7ce4721

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

builtin-index-pack.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,23 @@ static void unlink_base_data(struct base_data *c)
266266

267267
static void *unpack_entry_data(unsigned long offset, unsigned long size)
268268
{
269+
int status;
269270
z_stream stream;
270271
void *buf = xmalloc(size);
271272

272273
memset(&stream, 0, sizeof(stream));
274+
git_inflate_init(&stream);
273275
stream.next_out = buf;
274276
stream.avail_out = size;
275-
stream.next_in = fill(1);
276-
stream.avail_in = input_len;
277-
git_inflate_init(&stream);
278277

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 {
286279
stream.next_in = fill(1);
287280
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);
289286
git_inflate_end(&stream);
290287
return buf;
291288
}

0 commit comments

Comments
 (0)