{"thread":{"id":"11590","subject":"[PATCH 5/6] Convert builtin-pack/unpack","startedAt":"2008-01-11T18:58:56Z","lastAt":"2008-01-11T18:58:56Z","messageCount":1,"participants":["Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"65048","messageId":"e5bfff550801111058t42b289e9w4fe6b48a57024701@mail.gmail.com","threadId":"11590","inReplyTo":null,"subject":"[PATCH 5/6] Convert builtin-pack/unpack","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T18:58:56Z","receivedAt":"2008-01-11T18:58:56Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"Also in this case decompression helper conversion\nis quite similar and not too complex, so they go\ntogether.\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n builtin-pack-objects.c   |   14 ++++++--------\n builtin-unpack-objects.c |   20 +++++++-------------\n 2 files changed, 13 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 66dedf9..d2865fe 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -302,19 +302,17 @@ static int check_pack_inflate(struct\n {\n \tz_stream stream;\n \tunsigned char fakebuf[4096], *in;\n+\tunsigned int in_size = 0;\n \tint st;\n\n-\tmemset(&stream, 0, sizeof(stream));\n-\tinflateInit(&stream);\n+\tdecompress_alloc(&stream);\n \tdo {\n-\t\tin = use_pack(p, w_curs, offset, &stream.avail_in);\n-\t\tstream.next_in = in;\n-\t\tstream.next_out = fakebuf;\n-\t\tstream.avail_out = sizeof(fakebuf);\n-\t\tst = inflate(&stream, Z_FINISH);\n+\t\tdecompress_into(&stream, fakebuf, sizeof(fakebuf));\n+\t\tin = use_pack(p, w_curs, offset, &in_size);\n+\t\tst = decompress_next_from(&stream, in, in_size, Z_FINISH);\n \t\toffset += stream.next_in - in;\n \t} while (st == Z_OK || st == Z_BUF_ERROR);\n-\tinflateEnd(&stream);\n+\tdecompress_free(&stream);\n \treturn (st == Z_STREAM_END &&\n \t\tstream.total_out == expect &&\n \t\tstream.total_in == len) ? 0 : -1;\ndiff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c\nindex 1e51865..f1a4883 100644\n--- a/builtin-unpack-objects.c\n+++ b/builtin-unpack-objects.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"object.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n@@ -61,23 +62,18 @@ static void use(int bytes)\n static void *get_data(unsigned long size)\n {\n \tz_stream stream;\n-\tvoid *buf = xmalloc(size);\n+\tunsigned char *buf = xmalloc(size);;\n\n-\tmemset(&stream, 0, sizeof(stream));\n-\n-\tstream.next_out = buf;\n-\tstream.avail_out = size;\n-\tstream.next_in = fill(1);\n-\tstream.avail_in = len;\n-\tinflateInit(&stream);\n+\tdecompress_alloc(&stream);\n+\tdecompress_into(&stream, buf, size);\n\n \tfor (;;) {\n-\t\tint ret = inflate(&stream, 0);\n+\t\tint ret = decompress_next_from(&stream, fill(1), len, Z_NO_FLUSH);\n \t\tuse(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\terror(\"inflate returned %d\\n\", ret);\n+\t\t\terror(\"decompress returned %d\\n\", ret);\n \t\t\tfree(buf);\n \t\t\tbuf = NULL;\n \t\t\tif (!recover)\n@@ -85,10 +81,8 @@ static void *get_data(unsigned long size)\n \t\t\thas_errors = 1;\n \t\t\tbreak;\n \t\t}\n-\t\tstream.next_in = fill(1);\n-\t\tstream.avail_in = len;\n \t}\n-\tinflateEnd(&stream);\n+\tdecompress_free(&stream);\n \treturn buf;\n }\n\n-- \n1.5.4.rc2.90.gf158-dirty\n"}]}