From cde8ea9c66e46ed6427499e0bc049d1d5c55379a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 9 Nov 2020 17:05:31 +0100 Subject: archive: support compression levels beyond 9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compression programs like zip, gzip, bzip2 and xz allow to adjust the trade-off between CPU cost and size gain with numerical options from -1 for fast compression and -9 for high compression ratio. zip also accepts -0 for storing files verbatim. git archive directly support these single-digit compression levels for ZIP output and passes them to filters like gzip. Zstandard additionally supports compression level options -10 to -19, or up to -22 with --ultra. This *seems* to work with git archive in most cases, e.g. it will produce an archive with -19 without complaining, but since it only supports single-digit compression level options this is the same as -1 -9 and thus -9. Allow git archive to accept multi-digit compression levels to support the full range supported by zstd. Explicitly reject them for the ZIP format, as otherwise deflateInit2() would just fail with a somewhat cryptic "stream consistency error". Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- archive-tar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'archive-tar.c') diff --git a/archive-tar.c b/archive-tar.c index f1a1447ebd..a971fdc0f6 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -374,7 +374,8 @@ static int tar_filter_config(const char *var, const char *value, void *data) ar = xcalloc(1, sizeof(*ar)); ar->name = xmemdupz(name, namelen); ar->write_archive = write_tar_filter_archive; - ar->flags = ARCHIVER_WANT_COMPRESSION_LEVELS; + ar->flags = ARCHIVER_WANT_COMPRESSION_LEVELS | + ARCHIVER_HIGH_COMPRESSION_LEVELS; ALLOC_GROW(tar_filters, nr_tar_filters + 1, alloc_tar_filters); tar_filters[nr_tar_filters++] = ar; } -- cgit v1.2.3