Skip to content

Commit 0e5826e

Browse files
committed
archive: use the internal zlib-based gzip compression by default
We just introduced support for compressing `.tar.gz` archives in the `git archive` process itself, using zlib directly instead of spawning `gzip`. While this takes less CPU time overall, on multi-core machines, this is slightly slower in terms of wall clock time (it seems to be in the ballpark of 15%). It does reduce the number of dependencies by one, though, which makes it desirable to turn that mode on by default. Changing the default benefits most notably the MinGit flavor of Git for Windows (which intends to support 3rd-party applications that want to use Git and want to bundle a minimal set of files for that purpose, i.e. stripping out all non-essential files such as interactive commands, Perl, and yes, also `gzip`). We also can now remove the `GZIP` prerequisite from quite a number of test cases in `t/t5000-tar-tree.sh`. This closes git-for-windows#1970 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4ea94a8 commit 0e5826e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

Documentation/git-archive.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ tar.<format>.command::
116116
format is given.
117117
+
118118
The "tar.gz" and "tgz" formats are defined automatically and default to
119-
`gzip -cn`. You may override them with custom commands.
119+
`:zlib`, triggering an in-process gzip compression. You may override
120+
them with custom commands, e.g. `gzip -cn` or `pigz -cn`.
120121

121122
tar.<format>.remote::
122123
If true, enable `<format>` for use by remote clients via

archive-tar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ void init_tar_archiver(void)
514514
int i;
515515
register_archiver(&tar_archiver);
516516

517-
tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
517+
tar_filter_config("tar.tgz.command", ":zlib", NULL);
518518
tar_filter_config("tar.tgz.remote", "true", NULL);
519-
tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
519+
tar_filter_config("tar.tar.gz.command", ":zlib", NULL);
520520
tar_filter_config("tar.tar.gz.remote", "true", NULL);
521521
git_config(git_tar_config, NULL);
522522
for (i = 0; i < nr_tar_filters; i++) {

t/t5000-tar-tree.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,36 +291,41 @@ test_expect_success 'only enabled filters are available remotely' '
291291
test_cmp_bin remote.bar config.bar
292292
'
293293

294-
test_expect_success GZIP 'git archive --format=tgz' '
294+
test_expect_success 'git archive --format=tgz' '
295295
git archive --format=tgz HEAD >j.tgz
296296
'
297297

298-
test_expect_success GZIP 'git archive --format=tar.gz' '
298+
test_expect_success 'git archive --format=tar.gz' '
299299
git archive --format=tar.gz HEAD >j1.tar.gz &&
300300
test_cmp_bin j.tgz j1.tar.gz
301301
'
302302

303-
test_expect_success GZIP 'infer tgz from .tgz filename' '
303+
test_expect_success 'infer tgz from .tgz filename' '
304304
git archive --output=j2.tgz HEAD &&
305305
test_cmp_bin j.tgz j2.tgz
306306
'
307307

308-
test_expect_success GZIP 'infer tgz from .tar.gz filename' '
308+
test_expect_success 'infer tgz from .tar.gz filename' '
309309
git archive --output=j3.tar.gz HEAD &&
310310
test_cmp_bin j.tgz j3.tar.gz
311311
'
312312

313+
test_expect_success 'use `archive.tgz.command=:zlib` explicitly' '
314+
git -c archive.tgz.command=:zlib archive --output=j4.tgz HEAD &&
315+
test_cmp_bin j.tgz j4.tgz
316+
'
317+
313318
test_expect_success GZIP 'extract tgz file' '
314319
gzip -d -c <j.tgz >j.tar &&
315320
test_cmp_bin b.tar j.tar
316321
'
317322

318-
test_expect_success GZIP 'remote tar.gz is allowed by default' '
323+
test_expect_success 'remote tar.gz is allowed by default' '
319324
git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
320325
test_cmp_bin j.tgz remote.tar.gz
321326
'
322327

323-
test_expect_success GZIP 'remote tar.gz can be disabled' '
328+
test_expect_success 'remote tar.gz can be disabled' '
324329
git config tar.tar.gz.remote false &&
325330
test_must_fail git archive --remote=. --format=tar.gz HEAD \
326331
>remote.tar.gz

0 commit comments

Comments
 (0)