{"thread":{"id":"14526","subject":"[PATCH 1/2] archive: make zip compression level independent from core git","startedAt":"2008-07-18T14:30:32Z","lastAt":"2008-07-18T14:30:32Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"83880","messageId":"4880A908.9010206@lsrfire.ath.cx","threadId":"14526","inReplyTo":null,"subject":"[PATCH 1/2] archive: make zip compression level independent from core git","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-07-18T14:30:32Z","receivedAt":"2008-07-18T14:30:32Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"zlib_compression_level is the compression level used for git's object store.\nIt's 1 by default, which is the fastest setting.  This variable is also used\nas the default compression level for ZIP archives created by git archive.\n\nFor archives, however, zlib's own default of 6 is more appropriate, as it's\nfavouring small size over speed -- archive creation is not that performance\ncritical most of the time.\n\nThis patch makes git archive independent from git's internal compression\nlevel setting.  It affects invocations of git archive without explicitly\nspecified compression level option, only.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n archive-zip.c     |    9 +++++----\n archive.h         |    1 +\n builtin-archive.c |    3 ++-\n 3 files changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git a/archive-zip.c b/archive-zip.c\nindex d56e5cf..fb12398 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -93,7 +93,7 @@ static void copy_le32(unsigned char *dest, unsigned int n)\n }\n \n static void *zlib_deflate(void *data, unsigned long size,\n-                          unsigned long *compressed_size)\n+\t\tint compression_level, unsigned long *compressed_size)\n {\n \tz_stream stream;\n \tunsigned long maxsize;\n@@ -101,7 +101,7 @@ static void *zlib_deflate(void *data, unsigned long size,\n \tint result;\n \n \tmemset(&stream, 0, sizeof(stream));\n-\tdeflateInit(&stream, zlib_compression_level);\n+\tdeflateInit(&stream, compression_level);\n \tmaxsize = deflateBound(&stream, size);\n \tbuffer = xmalloc(maxsize);\n \n@@ -157,7 +157,7 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tmethod = 0;\n \t\tattr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :\n \t\t\t(mode & 0111) ? ((mode) << 16) : 0;\n-\t\tif (S_ISREG(mode) && zlib_compression_level != 0)\n+\t\tif (S_ISREG(mode) && args->compression_level != 0)\n \t\t\tmethod = 8;\n \t\tcrc = crc32(crc, buffer, size);\n \t\tout = buffer;\n@@ -169,7 +169,8 @@ static int write_zip_entry(struct archiver_args *args,\n \t}\n \n \tif (method == 8) {\n-\t\tdeflated = zlib_deflate(buffer, size, &compressed_size);\n+\t\tdeflated = zlib_deflate(buffer, size, args->compression_level,\n+\t\t\t\t&compressed_size);\n \t\tif (deflated && compressed_size - 6 < size) {\n \t\t\t/* ZLIB --> raw compressed data (see RFC 1950) */\n \t\t\t/* CMF and FLG ... */\ndiff --git a/archive.h b/archive.h\nindex 96bb1cd..4a02371 100644\n--- a/archive.h\n+++ b/archive.h\n@@ -13,6 +13,7 @@ struct archiver_args {\n \ttime_t time;\n \tconst char **pathspec;\n \tunsigned int verbose : 1;\n+\tint compression_level;\n };\n \n typedef int (*write_archive_fn_t)(struct archiver_args *);\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex d5e3af8..cff6ce7 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -185,9 +185,10 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,\n \tif (!*ar)\n \t\tdie(\"Unknown archive format '%s'\", format);\n \n+\targs->compression_level = Z_DEFAULT_COMPRESSION;\n \tif (compression_level != -1) {\n \t\tif ((*ar)->flags & USES_ZLIB_COMPRESSION)\n-\t\t\tzlib_compression_level = compression_level;\n+\t\t\targs->compression_level = compression_level;\n \t\telse {\n \t\t\tdie(\"Argument not supported for format '%s': -%d\",\n \t\t\t\t\tformat, compression_level);\n-- \n1.5.6.2.212.g08b51\n"}]}