{"thread":{"id":"11579","subject":"[PATCH] Use new compress helpers in sha1_file.c","startedAt":"2008-01-11T07:41:36Z","lastAt":"2008-01-11T07:41:36Z","messageCount":1,"participants":["Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64993","messageId":"e5bfff550801102341o5be9c1a7pedd94fb39b21b1ff@mail.gmail.com","threadId":"11579","inReplyTo":null,"subject":"[PATCH] Use new compress helpers in sha1_file.c","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T07:41:36Z","receivedAt":"2008-01-11T07:41:36Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"A multistep compress is required here, so\nwe need the full arsenal of compress helpers.\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n sha1_file.c |   41 ++++++++++++-----------------------------\n 1 files changed, 12 insertions(+), 29 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 6583797..6c94bd5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -7,6 +7,7 @@\n  * creation etc.\n  */\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"blob.h\"\n@@ -2086,33 +2087,23 @@ int write_sha1_file(void *buf, unsigned long\n \t}\n\n \t/* Set it up */\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n-\tsize = 8 + deflateBound(&stream, len+hdrlen);\n+\tsize = 8 + compress_alloc(&stream, zlib_compression_level, len+hdrlen);\n \tcompressed = xmalloc(size);\n\n \t/* Compress it */\n-\tstream.next_out = compressed;\n-\tstream.avail_out = size;\n+\tcompress_start(&stream, (unsigned char *)hdr, hdrlen, compressed, size);\n\n \t/* First header.. */\n-\tstream.next_in = (unsigned char *)hdr;\n-\tstream.avail_in = hdrlen;\n-\twhile (deflate(&stream, 0) == Z_OK)\n-\t\t/* nothing */;\n+\tcompress_next(&stream, Z_NO_FLUSH);\n\n \t/* Then the data itself.. */\n \tstream.next_in = buf;\n \tstream.avail_in = len;\n-\tret = deflate(&stream, Z_FINISH);\n+\tret = compress_next(&stream, Z_FINISH);\n \tif (ret != Z_STREAM_END)\n \t\tdie(\"unable to deflate new object %s (%d)\", sha1_to_hex(sha1), ret);\n\n-\tret = deflateEnd(&stream);\n-\tif (ret != Z_OK)\n-\t\tdie(\"deflateEnd on object %s failed (%d)\", sha1_to_hex(sha1), ret);\n-\n-\tsize = stream.total_out;\n+\tsize = compress_free(&stream);\n\n \tif (write_buffer(fd, compressed, size) < 0)\n \t\tdie(\"unable to write sha1 file\");\n@@ -2147,30 +2138,22 @@ static void *repack_object(const unsigned char *sha1,\n \thdrlen = sprintf(hdr, \"%s %lu\", typename(type), len) + 1;\n\n \t/* Set it up */\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n-\tsize = deflateBound(&stream, len + hdrlen);\n+\tsize = compress_alloc(&stream, zlib_compression_level, len + hdrlen);\n \tbuf = xmalloc(size);\n\n \t/* Compress it */\n-\tstream.next_out = buf;\n-\tstream.avail_out = size;\n+\tcompress_start(&stream, (unsigned char *)hdr, hdrlen, buf, size);\n\n \t/* First header.. */\n-\tstream.next_in = (void *)hdr;\n-\tstream.avail_in = hdrlen;\n-\twhile (deflate(&stream, 0) == Z_OK)\n-\t\t/* nothing */;\n+\tcompress_next(&stream, Z_NO_FLUSH);\n\n \t/* Then the data itself.. */\n \tstream.next_in = unpacked;\n \tstream.avail_in = len;\n-\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n-\t\t/* nothing */;\n-\tdeflateEnd(&stream);\n-\tfree(unpacked);\n+\tcompress_next(&stream, Z_FINISH);\n\n-\t*objsize = stream.total_out;\n+\t*objsize = compress_free(&stream);\n+\tfree(unpacked);\n \treturn buf;\n }\n\n-- \n1.5.4.rc2.89.g1b3f-dirty\n"}]}