{"thread":{"id":"11567","subject":"[PATCH 1/5] Add zlib decompress helper functions","startedAt":"2008-01-10T21:04:46Z","lastAt":"2008-01-10T22:04:00Z","messageCount":3,"participants":["Marco Costalba","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"64946","messageId":"e5bfff550801101304m4f0b97baua6553c45772793b6@mail.gmail.com","threadId":"11567","inReplyTo":null,"subject":"[PATCH 1/5] Add zlib decompress helper functions","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-10T21:04:46Z","receivedAt":"2008-01-10T21:04:46Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"When decompressing a zlib stream use this\nhelpers instead of calling low level zlib\nfunction.\n\nThis patch introduces the necessary framework,\nstill no code change.\n\nThis is the first step in generalizing compress and\ndecompress functions avoiding zlib directly calls.\n\nSigned-off-by: Marco Costalba <mcostalba@gmail.com>\n---\n\n Makefile   |    4 ++--\n compress.c |   52 ++++++++++++++++++++++++++\n compress.h |   14 ++++++++++++++\n 3 files changed, 68 insertions(+), 2 deletions(-)\n create mode 100644 compress.c\n create mode 100644 compress.h\n\ndiff --git a/Makefile b/Makefile\nindex 21c80e6..89bd99d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -288,7 +288,7 @@ LIB_FILE=libgit.a\n XDIFF_LIB=xdiff/lib.a\n\n LIB_H = \\\n-\tarchive.h blob.h cache.h cache-tree.h commit.h csum-file.h delta.h grep.h \\\n+\tarchive.h blob.h cache.h cache-tree.h commit.h compress.h\ncsum-file.h delta.h grep.h \\\n \tdiff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \\\n \trun-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \\\n \ttree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \\\n@@ -301,7 +301,7 @@ DIFF_OBJS = \\\n \tdiffcore-delta.o log-tree.o\n\n LIB_OBJS = \\\n-\tblob.o commit.o connect.o csum-file.o cache-tree.o base85.o \\\n+\tblob.o commit.o compress.o connect.o csum-file.o cache-tree.o base85.o \\\n \tdate.o diff-delta.o entry.o exec_cmd.o ident.o \\\n \tpretty.o interpolate.o hash.o \\\n \tlockfile.o \\\ndiff --git a/compress.c b/compress.c\nnew file mode 100644\nindex 0000000..f40e09c\n--- /dev/null\n+++ b/compress.c\n@@ -0,0 +1,52 @@\n+#include \"cache.h\"\n+#include \"compress.h\"\n+\n+unsigned long z_deflate_init(z_stream *stream, int level, unsigned long size)\n+{\n+\tmemset(stream, 0, sizeof(*stream));\n+\tdeflateInit(stream, level);\n+\treturn deflateBound(stream, size);\n+}\n+\n+int z_deflate_start(z_stream *stream, unsigned char *in, unsigned long in_size,\n+                    unsigned char *out, unsigned long out_size)\n+{\n+\tstream->next_out = (out ? out : xmalloc(out_size));\n+\tstream->avail_out = out_size;\n+\tstream->next_in = in;\n+\tstream->avail_in = in_size;\n+\treturn Z_OK;\n+}\n+\n+int z_deflate_next(z_stream *stream, int flush)\n+{\n+\tint result;\n+\n+\tdo {\n+\t\tresult = deflate(stream, flush);\n+\t} while (result == Z_OK);\n+\n+\treturn result;\n+}\n+\n+unsigned long z_deflate_all(int level, unsigned char *data,\n+                            unsigned long size, unsigned char **out)\n+{\n+\tint bound, result;\n+\tz_stream stream;\n+\n+\tbound = z_deflate_init(&stream, level, size);\n+\tz_deflate_start(&stream, data, size, NULL, bound);\n+\n+\t*out = stream.next_out;\n+\tresult = z_deflate_next(&stream, Z_FINISH);\n+\n+\tif (result != Z_STREAM_END) {\n+\t\tdeflateEnd(&stream);\n+\t\tfree(*out);\n+\t\t*out = NULL;\n+\t\treturn 0;\n+\t}\n+\tdeflateEnd(&stream);\n+\treturn stream.total_out;\n+}\ndiff --git a/compress.h b/compress.h\nnew file mode 100644\nindex 0000000..926450c\n--- /dev/null\n+++ b/compress.h\n@@ -0,0 +1,14 @@\n+#ifndef COMPRESS_H\n+#define COMPRESS_H\n+\n+extern unsigned long z_deflate_init(z_stream *stream, int level,\nunsigned long size);\n+\n+extern int z_deflate_start(z_stream *stream, unsigned char *in,\nunsigned long in_size,\n+                           unsigned char *out, unsigned long out_size);\n+\n+extern int z_deflate_next(z_stream *stream, int flush);\n+\n+extern unsigned long z_deflate_all(int level, unsigned char *data,\n+                                   unsigned long size, unsigned char **out);\n+\n+#endif\n-- \n1.5.4.rc2.89.g1b3f\n"},{"id":"64959","messageId":"alpine.LFD.1.00.0801101351250.3148@woody.linux-foundation.org","threadId":"11567","inReplyTo":"e5bfff550801101304m4f0b97baua6553c45772793b6@mail.gmail.com","subject":"Re: [PATCH 1/5] Add zlib decompress helper functions","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-01-10T21:57:40Z","receivedAt":"2008-01-10T21:57:40Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 10 Jan 2008, Marco Costalba wrote:\n>\n> When decompressing a zlib stream use this\n> helpers instead of calling low level zlib\n> function.\n\nI really *really* hate your naming.\n\n> This is the first step in generalizing compress and\n> decompress functions avoiding zlib directly calls.\n\nIf that's the goal, why keep the horrible \"z_\" prefix, and why the opaque \nand non-obvious \"inflate\"/\"deflate\" names?\n\nI'd suggest that you just replace all \"z_deflate_\" with \"compress_\" and \n\"z_inflate_\" with \"decompress_\".\n\nYes, it would still leave zlib-specific stuff in there (the return codes, \nthe \"z_stream\" type thing etc), but at least it would be a _step_ towards \nmore readable code and code that is less obviously zlib-specific.\n\nWith those changes, I'd heartily recommend merging this even if we never \nactually switch away from zlib, if only because zlib has all these \nhorrible names.\n\n\t\tLinus\n\n[ How many people really know that \"inflate\" means \"uncompress\", without \n  having to think about it a bit?\n\n  I guarantee that any computer person immediately knows the difference \n  between \"compress\" and \"decompress\" without even thinking, but ask \n  somebody what \"inflate\" vs \"deflate\" does, and they'll be able to answer \n  you, but they'll first have to think about an air mattress or something.\n\n  Yeah, yeah, old-time zip users probably think the whole xxflate thing \n  makes sense, and I'm just grouchy because _I_ always have to think \n  about it. ]\n"},{"id":"64961","messageId":"e5bfff550801101404g488354f5rb05cccf0923fbb9c@mail.gmail.com","threadId":"11567","inReplyTo":"alpine.LFD.1.00.0801101351250.3148@woody.linux-foundation.org","subject":"Re: [PATCH 1/5] Add zlib decompress helper functions","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2008-01-10T22:04:00Z","receivedAt":"2008-01-10T22:04:00Z","isPatch":true,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On Jan 10, 2008 10:57 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:\n>\n>\n> On Thu, 10 Jan 2008, Marco Costalba wrote:\n> >\n> > When decompressing a zlib stream use this\n> > helpers instead of calling low level zlib\n> > function.\n>\n> I really *really* hate your naming.\n>\n\nI agree 100% it was chosen only to keep zlib conventions.\n\n>\n> [ How many people really know that \"inflate\" means \"uncompress\", without\n>   having to think about it a bit?\n>\n\nI misnamed the whole patch series but the last one due to deflate\nbeing tot intuitive !!!\n\nOk I wrote the e-mails very quickly and cut and paste was heavily\ninvolved, but when I realized that I called all the series 'decompress\nhelpers' I went blush!\n\nMarco\n"}]}