{"thread":{"id":"11576","subject":"[PATCH 2/5] Use new compress helpers in git files","startedAt":"2008-01-11T07:37:15Z","lastAt":"2008-01-11T15:29:17Z","messageCount":2,"participants":["Marco Costalba","Kristian Høgsberg"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"64990","messageId":"e5bfff550801102337w1afc6c88n2c60f26fa80d8da4@mail.gmail.com","threadId":"11576","inReplyTo":null,"subject":"[PATCH 2/5] Use new compress helpers in git files","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T07:37:15Z","receivedAt":"2008-01-11T07:37:15Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"These are the 'easy' ones, where a signgle step\ncompression is requested so that we can use only\none call to compress_all()\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n archive-zip.c          |   28 +++-------------------------\n builtin-pack-objects.c |   21 ++++-----------------\n diff.c                 |   22 +++++-----------------\n index-pack.c           |   20 +++-----------------\n 4 files changed, 15 insertions(+), 76 deletions(-)\n\ndiff --git a/archive-zip.c b/archive-zip.c\nindex 74e30f6..9071b86 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -3,6 +3,7 @@\n  */\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"compress.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n #include \"quote.h\"\n@@ -97,33 +98,10 @@ static void copy_le32(unsigned char *dest,\n static void *zlib_deflate(void *data, unsigned long size,\n                           unsigned long *compressed_size)\n {\n-\tz_stream stream;\n-\tunsigned long maxsize;\n-\tvoid *buffer;\n-\tint result;\n-\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n-\tmaxsize = deflateBound(&stream, size);\n-\tbuffer = xmalloc(maxsize);\n-\n-\tstream.next_in = data;\n-\tstream.avail_in = size;\n-\tstream.next_out = buffer;\n-\tstream.avail_out = maxsize;\n-\n-\tdo {\n-\t\tresult = deflate(&stream, Z_FINISH);\n-\t} while (result == Z_OK);\n-\n-\tif (result != Z_STREAM_END) {\n-\t\tfree(buffer);\n-\t\treturn NULL;\n-\t}\n\n-\tdeflateEnd(&stream);\n-\t*compressed_size = stream.total_out;\n+\tunsigned char *buffer = NULL;\n\n+\t*compressed_size = compress_all(zlib_compression_level, data, size, &buffer);\n \treturn buffer;\n }\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex a39cb82..66dedf9 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -1,5 +1,6 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\n@@ -409,9 +410,7 @@ static unsigned long write_object(struct sha1file *f,\n \t\t\t\t */\n\n \tif (!to_reuse) {\n-\t\tz_stream stream;\n-\t\tunsigned long maxsize;\n-\t\tvoid *out;\n+\t\tunsigned char *out = NULL;\n \t\tif (!usable_delta) {\n \t\t\tbuf = read_sha1_file(entry->idx.sha1, &obj_type, &size);\n \t\t\tif (!buf)\n@@ -432,20 +431,8 @@ static unsigned long write_object(struct sha1file *f,\n \t\t\t\tOBJ_OFS_DELTA : OBJ_REF_DELTA;\n \t\t}\n \t\t/* compress the data to store and put compressed length in datalen */\n-\t\tmemset(&stream, 0, sizeof(stream));\n-\t\tdeflateInit(&stream, pack_compression_level);\n-\t\tmaxsize = deflateBound(&stream, size);\n-\t\tout = xmalloc(maxsize);\n-\t\t/* Compress it */\n-\t\tstream.next_in = buf;\n-\t\tstream.avail_in = size;\n-\t\tstream.next_out = out;\n-\t\tstream.avail_out = maxsize;\n-\t\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n-\t\t\t/* nothing */;\n-\t\tdeflateEnd(&stream);\n-\t\tdatalen = stream.total_out;\n-\t\tdeflateEnd(&stream);\n+\t\tdatalen = compress_all(pack_compression_level, buf, size, &out);\n+\n \t\t/*\n \t\t * The object header is a byte of 'type' followed by zero or\n \t\t * more bytes of length.\ndiff --git a/diff.c b/diff.c\nindex b18c140..43f537c 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2,6 +2,7 @@\n  * Copyright (C) 2005 Junio C Hamano\n  */\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"quote.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -1037,23 +1038,10 @@ static unsigned char *deflate_it(char *data,\n \t\t\t\t unsigned long size,\n \t\t\t\t unsigned long *result_size)\n {\n-\tint bound;\n-\tunsigned char *deflated;\n-\tz_stream stream;\n-\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n-\tbound = deflateBound(&stream, size);\n-\tdeflated = xmalloc(bound);\n-\tstream.next_out = deflated;\n-\tstream.avail_out = bound;\n-\n-\tstream.next_in = (unsigned char *)data;\n-\tstream.avail_in = size;\n-\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n-\t\t; /* nothing */\n-\tdeflateEnd(&stream);\n-\t*result_size = stream.total_out;\n+\tunsigned char *deflated = NULL;\n+\n+\t*result_size = compress_all(zlib_compression_level,\n+                                   (unsigned char *)data, size, &deflated);\n \treturn deflated;\n }\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 9fd6982..880088e 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"csum-file.h\"\n@@ -494,24 +495,9 @@ static void parse_pack_objects(unsigned char\n\n static int write_compressed(int fd, void *in, unsigned int size,\nuint32_t *obj_crc)\n {\n-\tz_stream stream;\n-\tunsigned long maxsize;\n-\tvoid *out;\n+\tunsigned char *out = NULL;\n\n-\tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n-\tmaxsize = deflateBound(&stream, size);\n-\tout = xmalloc(maxsize);\n-\n-\t/* Compress it */\n-\tstream.next_in = in;\n-\tstream.avail_in = size;\n-\tstream.next_out = out;\n-\tstream.avail_out = maxsize;\n-\twhile (deflate(&stream, Z_FINISH) == Z_OK);\n-\tdeflateEnd(&stream);\n-\n-\tsize = stream.total_out;\n+\tsize = compress_all(zlib_compression_level, in, size, &out);\n \twrite_or_die(fd, out, size);\n \t*obj_crc = crc32(*obj_crc, out, size);\n \tfree(out);\n-- \n1.5.4.rc2.89.g1b3f-dirty\n"},{"id":"65026","messageId":"1200065357.18570.2.camel@gaara.boston.redhat.com","threadId":"11576","inReplyTo":"e5bfff550801102337w1afc6c88n2c60f26fa80d8da4@mail.gmail.com","subject":"Re: [PATCH 2/5] Use new compress helpers in git files","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2008-01-11T15:29:17Z","receivedAt":"2008-01-11T15:29:17Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"On Fri, 2008-01-11 at 08:37 +0100, Marco Costalba wrote:\n> These are the 'easy' ones, where a signgle step\n> compression is requested so that we can use only\n> one call to compress_all()\n> \n> Signed-off-by: Marco Costalba <mcostalba@gmail.com>\n> ---\n>  archive-zip.c          |   28 +++-------------------------\n>  builtin-pack-objects.c |   21 ++++-----------------\n>  diff.c                 |   22 +++++-----------------\n>  index-pack.c           |   20 +++-----------------\n>  4 files changed, 15 insertions(+), 76 deletions(-)\n> \n> diff --git a/archive-zip.c b/archive-zip.c\n> index 74e30f6..9071b86 100644\n> --- a/archive-zip.c\n> +++ b/archive-zip.c\n> @@ -3,6 +3,7 @@\n>   */\n>  #include \"cache.h\"\n>  #include \"commit.h\"\n> +#include \"compress.h\"\n>  #include \"blob.h\"\n>  #include \"tree.h\"\n>  #include \"quote.h\"\n> @@ -97,33 +98,10 @@ static void copy_le32(unsigned char *dest,\n>  static void *zlib_deflate(void *data, unsigned long size,\n>                            unsigned long *compressed_size)\n>  {\n\nHow about just getting rid of this function alltogether, since it seems\nto do more or less the same as your new compress_all() function?  Just\nchange the call-sites of zlib_deflate() to call compress_all() instead.\n\n> @@ -1037,23 +1038,10 @@ static unsigned char *deflate_it(char *data,\n>  \t\t\t\t unsigned long size,\n>  \t\t\t\t unsigned long *result_size)\n>  {\n\nSame here.\n\ncheers,\nKristian\n"}]}