archive: provide builtin .tar.gz filter
This works exactly as if the user had configured it via: [tar "tgz"] command = gzip -cn [tar "tar.gz"] command = gzip -cn but since it is so common, it's convenient to have it builtin without the user needing to do anything. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 21, 2011 at 21:27 UTC
0e804e09938905ed4fe6984f832057267cc5d86f
3 files changed
+51
Documentation/git-archive.txt
+11
@@ -110,6 +110,9 @@ tar.<format>.command::
110
to the command (e.g., "-9"). An output file with the same
111
extension as `<format>` will be use this format if no other
112
format is given.
113
++
114
+The "tar.gz" and "tgz" formats are defined automatically and default to
115
+`gzip -cn`. You may override them with custom commands.
116
117
ATTRIBUTES
118
----------
@@ -143,6 +146,14 @@ git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz::
146
147
Create a compressed tarball for v1.4.0 release.
148
149
+git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz::
150
+
151
+ Same as above, but using the builtin tar.gz handling.
152
+
153
+git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0::
154
+
155
+ Same as above, but the format is inferred from the output file.
156
+
157
git archive --format=tar --prefix=git-1.4.0/ v1.4.0{caret}\{tree\} | gzip >git-1.4.0.tar.gz::
158
159
Create a compressed tarball for v1.4.0 release, but without a
archive-tar.c
+2
@@ -357,6 +357,8 @@ void init_tar_archiver(void)
357
int i;
358
register_archiver(&tar_archiver);
359
360
+ tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
361
+ tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
362
git_config(git_tar_config, NULL);
363
for (i = 0; i < nr_tar_filters; i++) {
364
/* omit any filters that never had a command configured */
t/t5000-tar-tree.sh
+38
@@ -26,6 +26,8 @@ commit id embedding:
26
27
. ./test-lib.sh
28
UNZIP=${UNZIP:-unzip}
29
+GZIP=${GZIP:-gzip}
30
+GUNZIP=${GUNZIP:-gzip -d}
31
32
SUBSTFORMAT=%H%n
33
@@ -295,4 +297,40 @@ test_expect_success 'extension matching requires dot' '
297
test_cmp b.tar config-implicittar.foo
298
'
299
300
+if $GZIP --version >/dev/null 2>&1; then
301
+ test_set_prereq GZIP
302
+else
303
+ say "Skipping some tar.gz tests because gzip not found"
304
+fi
305
+
306
+test_expect_success GZIP 'git archive --format=tgz' '
307
+ git archive --format=tgz HEAD >j.tgz
308
+'
309
+
310
+test_expect_success GZIP 'git archive --format=tar.gz' '
311
+ git archive --format=tar.gz HEAD >j1.tar.gz &&
312
+ test_cmp j.tgz j1.tar.gz
313
+'
314
+
315
+test_expect_success GZIP 'infer tgz from .tgz filename' '
316
+ git archive --output=j2.tgz HEAD &&
317
+ test_cmp j.tgz j2.tgz
318
+'
319
+
320
+test_expect_success GZIP 'infer tgz from .tar.gz filename' '
321
+ git archive --output=j3.tar.gz HEAD &&
322
+ test_cmp j.tgz j3.tar.gz
323
+'
324
+
325
+if $GUNZIP --version >/dev/null 2>&1; then
326
+ test_set_prereq GUNZIP
327
+else
328
+ say "Skipping some tar.gz tests because gunzip was not found"
329
+fi
330
+
331
+test_expect_success GZIP,GUNZIP 'extract tgz file' '
332
+ $GUNZIP -c <j.tgz >j.tar &&
333
+ test_cmp b.tar j.tar
334
+'
335
+
336
test_done