@matheusbsbs / matheus-bagliano / commits / 3a176c6cde
Fork 0

archive: make zip compression level independent from core git

zlib_compression_level is the compression level used for git's object store. It's 1 by default, which is the fastest setting. This variable is also used as the default compression level for ZIP archives created by git archive. For archives, however, zlib's own default of 6 is more appropriate, as it's favouring small size over speed -- archive creation is not that performance critical most of the time. This patch makes git archive independent from git's internal compression level setting. It affects invocations of git archive without explicitly specified compression level option, only. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 18, 2008 at 16:30 UTC 3a176c6cde650f8907b2dbafafb72f6375038613
3 files changed +8 -5
archive-zip.c
+5 -4
@@ -93,7 +93,7 @@ static void copy_le32(unsigned char *dest, unsigned int n)
93 }
94
95 static void *zlib_deflate(void *data, unsigned long size,
96 - unsigned long *compressed_size)
96 + int compression_level, unsigned long *compressed_size)
97 {
98 z_stream stream;
99 unsigned long maxsize;
@@ -101,7 +101,7 @@ static void *zlib_deflate(void *data, unsigned long size,
101 int result;
102
103 memset(&stream, 0, sizeof(stream));
104 - deflateInit(&stream, zlib_compression_level);
104 + deflateInit(&stream, compression_level);
105 maxsize = deflateBound(&stream, size);
106 buffer = xmalloc(maxsize);
107
@@ -157,7 +157,7 @@ static int write_zip_entry(struct archiver_args *args,
157 method = 0;
158 attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
159 (mode & 0111) ? ((mode) << 16) : 0;
160 - if (S_ISREG(mode) && zlib_compression_level != 0)
160 + if (S_ISREG(mode) && args->compression_level != 0)
161 method = 8;
162 crc = crc32(crc, buffer, size);
163 out = buffer;
@@ -169,7 +169,8 @@ static int write_zip_entry(struct archiver_args *args,
169 }
170
171 if (method == 8) {
172 - deflated = zlib_deflate(buffer, size, &compressed_size);
172 + deflated = zlib_deflate(buffer, size, args->compression_level,
173 + &compressed_size);
174 if (deflated && compressed_size - 6 < size) {
175 /* ZLIB --> raw compressed data (see RFC 1950) */
176 /* CMF and FLG ... */
archive.h
+1
@@ -13,6 +13,7 @@ struct archiver_args {
13 time_t time;
14 const char **pathspec;
15 unsigned int verbose : 1;
16 + int compression_level;
17 };
18
19 typedef int (*write_archive_fn_t)(struct archiver_args *);
builtin-archive.c
+2 -1
@@ -185,9 +185,10 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
185 if (!*ar)
186 die("Unknown archive format '%s'", format);
187
188 + args->compression_level = Z_DEFAULT_COMPRESSION;
189 if (compression_level != -1) {
190 if ((*ar)->flags & USES_ZLIB_COMPRESSION)
190 - zlib_compression_level = compression_level;
191 + args->compression_level = compression_level;
192 else {
193 die("Argument not supported for format '%s': -%d",
194 format, compression_level);