{"thread":{"id":"23431","subject":"[PATCH v2 2/2] index-pack: rationalize unpack_entry_data()","startedAt":"2010-04-12T16:12:06Z","lastAt":"2010-04-12T16:12:06Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"139352","messageId":"alpine.LFD.2.00.1004121211100.7232@xanadu.home","threadId":"23431","inReplyTo":null,"subject":"[PATCH v2 2/2] index-pack: rationalize unpack_entry_data()","fromName":"Nicolas Pitre","fromEmail":"nico@fluxnic.net","sentAt":"2010-04-12T16:12:06Z","receivedAt":"2010-04-12T16:12:06Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"\nRework the loop to remove duplicated calls to use() and fill(), and\nto make the code easier to read.\n\nSigned-off-by: Nicolas Pitre <nico@fluxnic.net>\n---\n builtin/index-pack.c |   19 ++++++++-----------\n 1 files changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 127e713..4308abb 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -266,26 +266,23 @@ static void unlink_base_data(struct base_data *c)\n \n static void *unpack_entry_data(unsigned long offset, unsigned long size)\n {\n+\tint status;\n \tz_stream stream;\n \tvoid *buf = xmalloc(size);\n \n \tmemset(&stream, 0, sizeof(stream));\n+\tgit_inflate_init(&stream);\n \tstream.next_out = buf;\n \tstream.avail_out = size;\n-\tstream.next_in = fill(1);\n-\tstream.avail_in = input_len;\n-\tgit_inflate_init(&stream);\n \n-\tfor (;;) {\n-\t\tint ret = git_inflate(&stream, 0);\n-\t\tuse(input_len - stream.avail_in);\n-\t\tif (stream.total_out == size && ret == Z_STREAM_END)\n-\t\t\tbreak;\n-\t\tif (ret != Z_OK)\n-\t\t\tbad_object(offset, \"inflate returned %d\", ret);\n+\tdo {\n \t\tstream.next_in = fill(1);\n \t\tstream.avail_in = input_len;\n-\t}\n+\t\tstatus = git_inflate(&stream, 0);\n+\t\tuse(input_len - stream.avail_in);\n+\t} while (status == Z_OK);\n+\tif (stream.total_out != size || status != Z_STREAM_END)\n+\t\tbad_object(offset, \"inflate returned %d\", status);\n \tgit_inflate_end(&stream);\n \treturn buf;\n }\n-- \n1.7.1.rc1.237.ge1730.dirty\n"}]}