{"thread":{"id":"11577","subject":"[PATCH 3/5] Use new compress helpers in fast-import","startedAt":"2008-01-11T07:38:21Z","lastAt":"2008-01-11T07:38:21Z","messageCount":1,"participants":["Marco Costalba"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"64991","messageId":"e5bfff550801102338s6542be72r78029ecfc382559e@mail.gmail.com","threadId":"11577","inReplyTo":null,"subject":"[PATCH 3/5] Use new compress helpers in fast-import","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-11T07:38:21Z","receivedAt":"2008-01-11T07:38:21Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"Here is slightly more difficult, in particular\na xrealloc() has been substituted with a\nfree() + xmalloc() to keep the code simple.\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n fast-import.c |   44 +++++++++++++++------------------------\n 1 files changed, 15 insertions(+), 29 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 74597c9..6166d4a 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -141,6 +141,7 @@ Format of STDIN stream:\n\n #include \"builtin.h\"\n #include \"cache.h\"\n+#include \"compress.h\"\n #include \"object.h\"\n #include \"blob.h\"\n #include \"tree.h\"\n@@ -994,13 +995,13 @@ static int store_object(\n \tunsigned char *sha1out,\n \tuintmax_t mark)\n {\n-\tvoid *out, *delta;\n+\tunsigned char *out, *delta;\n \tstruct object_entry *e;\n \tunsigned char hdr[96];\n \tunsigned char sha1[20];\n \tunsigned long hdrlen, deltalen;\n \tSHA_CTX c;\n-\tz_stream s;\n+\tint out_size;\n\n \thdrlen = sprintf((char*)hdr,\"%s %lu\", typename(type),\n \t\t(unsigned long)dat->len) + 1;\n@@ -1036,24 +1037,15 @@ static int store_object(\n \t} else\n \t\tdelta = NULL;\n\n-\tmemset(&s, 0, sizeof(s));\n-\tdeflateInit(&s, zlib_compression_level);\n-\tif (delta) {\n-\t\ts.next_in = delta;\n-\t\ts.avail_in = deltalen;\n-\t} else {\n-\t\ts.next_in = (void *)dat->buf;\n-\t\ts.avail_in = dat->len;\n-\t}\n-\ts.avail_out = deflateBound(&s, s.avail_in);\n-\ts.next_out = out = xmalloc(s.avail_out);\n-\twhile (deflate(&s, Z_FINISH) == Z_OK)\n-\t\t/* nothing */;\n-\tdeflateEnd(&s);\n+\tif (delta)\n+\t\tout_size = compress_all(zlib_compression_level, delta, deltalen, &out);\n+\telse\n+\t\tout_size = compress_all(zlib_compression_level,\n+                                       (unsigned char *)dat->buf,\ndat->len, &out);\n\n \t/* Determine if we should auto-checkpoint. */\n-\tif ((pack_size + 60 + s.total_out) > max_packsize\n-\t\t|| (pack_size + 60 + s.total_out) < pack_size) {\n+\tif ((pack_size + 60 + out_size) > max_packsize\n+\t\t|| (pack_size + 60 + out_size) < pack_size) {\n\n \t\t/* This new object needs to *not* have the current pack_id. */\n \t\te->pack_id = pack_id + 1;\n@@ -1064,15 +1056,9 @@ static int store_object(\n \t\t\tfree(delta);\n \t\t\tdelta = NULL;\n\n-\t\t\tmemset(&s, 0, sizeof(s));\n-\t\t\tdeflateInit(&s, zlib_compression_level);\n-\t\t\ts.next_in = (void *)dat->buf;\n-\t\t\ts.avail_in = dat->len;\n-\t\t\ts.avail_out = deflateBound(&s, s.avail_in);\n-\t\t\ts.next_out = out = xrealloc(out, s.avail_out);\n-\t\t\twhile (deflate(&s, Z_FINISH) == Z_OK)\n-\t\t\t\t/* nothing */;\n-\t\t\tdeflateEnd(&s);\n+\t\t\tfree(out);\n+\t\t\tout_size = compress_all(zlib_compression_level,\n+                                               (unsigned char\n*)dat->buf, dat->len, &out);\n \t\t}\n \t}\n\n@@ -1105,8 +1091,8 @@ static int store_object(\n \t\tpack_size += hdrlen;\n \t}\n\n-\twrite_or_die(pack_data->pack_fd, out, s.total_out);\n-\tpack_size += s.total_out;\n+\twrite_or_die(pack_data->pack_fd, out, out_size);\n+\tpack_size += out_size;\n\n \tfree(out);\n \tfree(delta);\n-- \n1.5.4.rc2.89.g1b3f-dirty\n"}]}