Skip to content

Commit 3a176c6

Browse files
René Scharfegitster
authored andcommitted
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>
1 parent 6259ac6 commit 3a176c6

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

archive-zip.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ static void copy_le32(unsigned char *dest, unsigned int n)
9393
}
9494

9595
static void *zlib_deflate(void *data, unsigned long size,
96-
unsigned long *compressed_size)
96+
int compression_level, unsigned long *compressed_size)
9797
{
9898
z_stream stream;
9999
unsigned long maxsize;
100100
void *buffer;
101101
int result;
102102

103103
memset(&stream, 0, sizeof(stream));
104-
deflateInit(&stream, zlib_compression_level);
104+
deflateInit(&stream, compression_level);
105105
maxsize = deflateBound(&stream, size);
106106
buffer = xmalloc(maxsize);
107107

@@ -157,7 +157,7 @@ static int write_zip_entry(struct archiver_args *args,
157157
method = 0;
158158
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
159159
(mode & 0111) ? ((mode) << 16) : 0;
160-
if (S_ISREG(mode) && zlib_compression_level != 0)
160+
if (S_ISREG(mode) && args->compression_level != 0)
161161
method = 8;
162162
crc = crc32(crc, buffer, size);
163163
out = buffer;
@@ -169,7 +169,8 @@ static int write_zip_entry(struct archiver_args *args,
169169
}
170170

171171
if (method == 8) {
172-
deflated = zlib_deflate(buffer, size, &compressed_size);
172+
deflated = zlib_deflate(buffer, size, args->compression_level,
173+
&compressed_size);
173174
if (deflated && compressed_size - 6 < size) {
174175
/* ZLIB --> raw compressed data (see RFC 1950) */
175176
/* CMF and FLG ... */

archive.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct archiver_args {
1313
time_t time;
1414
const char **pathspec;
1515
unsigned int verbose : 1;
16+
int compression_level;
1617
};
1718

1819
typedef int (*write_archive_fn_t)(struct archiver_args *);

builtin-archive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
185185
if (!*ar)
186186
die("Unknown archive format '%s'", format);
187187

188+
args->compression_level = Z_DEFAULT_COMPRESSION;
188189
if (compression_level != -1) {
189190
if ((*ar)->flags & USES_ZLIB_COMPRESSION)
190-
zlib_compression_level = compression_level;
191+
args->compression_level = compression_level;
191192
else {
192193
die("Argument not supported for format '%s': -%d",
193194
format, compression_level);

0 commit comments

Comments
 (0)