Skip to content

Commit 0e804e0

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 767cf45 commit 0e804e0

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Documentation/git-archive.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ tar.<format>.command::
110110
to the command (e.g., "-9"). An output file with the same
111111
extension as `<format>` will be use this format if no other
112112
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.
113116

114117
ATTRIBUTES
115118
----------
@@ -143,6 +146,14 @@ git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz::
143146

144147
Create a compressed tarball for v1.4.0 release.
145148

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+
146157
git archive --format=tar --prefix=git-1.4.0/ v1.4.0{caret}\{tree\} | gzip >git-1.4.0.tar.gz::
147158

148159
Create a compressed tarball for v1.4.0 release, but without a

archive-tar.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ void init_tar_archiver(void)
357357
int i;
358358
register_archiver(&tar_archiver);
359359

360+
tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
361+
tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
360362
git_config(git_tar_config, NULL);
361363
for (i = 0; i < nr_tar_filters; i++) {
362364
/* omit any filters that never had a command configured */

t/t5000-tar-tree.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ commit id embedding:
2626

2727
. ./test-lib.sh
2828
UNZIP=${UNZIP:-unzip}
29+
GZIP=${GZIP:-gzip}
30+
GUNZIP=${GUNZIP:-gzip -d}
2931

3032
SUBSTFORMAT=%H%n
3133

@@ -295,4 +297,40 @@ test_expect_success 'extension matching requires dot' '
295297
test_cmp b.tar config-implicittar.foo
296298
'
297299

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+
298336
test_done

0 commit comments

Comments
 (0)