Skip to content

Commit

Permalink
archive: provide builtin .tar.gz filter
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peff authored and gitster committed Jun 22, 2011
1 parent 767cf45 commit 0e804e0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Documentation/git-archive.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ tar.<format>.command::
to the command (e.g., "-9"). An output file with the same
extension as `<format>` will be use this format if no other
format is given.
+
The "tar.gz" and "tgz" formats are defined automatically and default to
`gzip -cn`. You may override them with custom commands.

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

Create a compressed tarball for v1.4.0 release.

git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz::

Same as above, but using the builtin tar.gz handling.

git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0::

Same as above, but the format is inferred from the output file.

git archive --format=tar --prefix=git-1.4.0/ v1.4.0{caret}\{tree\} | gzip >git-1.4.0.tar.gz::

Create a compressed tarball for v1.4.0 release, but without a
Expand Down
2 changes: 2 additions & 0 deletions archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ void init_tar_archiver(void)
int i;
register_archiver(&tar_archiver);

tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
git_config(git_tar_config, NULL);
for (i = 0; i < nr_tar_filters; i++) {
/* omit any filters that never had a command configured */
Expand Down
38 changes: 38 additions & 0 deletions t/t5000-tar-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ commit id embedding:

. ./test-lib.sh
UNZIP=${UNZIP:-unzip}
GZIP=${GZIP:-gzip}
GUNZIP=${GUNZIP:-gzip -d}

SUBSTFORMAT=%H%n

Expand Down Expand Up @@ -295,4 +297,40 @@ test_expect_success 'extension matching requires dot' '
test_cmp b.tar config-implicittar.foo
'

if $GZIP --version >/dev/null 2>&1; then
test_set_prereq GZIP
else
say "Skipping some tar.gz tests because gzip not found"
fi

test_expect_success GZIP 'git archive --format=tgz' '
git archive --format=tgz HEAD >j.tgz
'

test_expect_success GZIP 'git archive --format=tar.gz' '
git archive --format=tar.gz HEAD >j1.tar.gz &&
test_cmp j.tgz j1.tar.gz
'

test_expect_success GZIP 'infer tgz from .tgz filename' '
git archive --output=j2.tgz HEAD &&
test_cmp j.tgz j2.tgz
'

test_expect_success GZIP 'infer tgz from .tar.gz filename' '
git archive --output=j3.tar.gz HEAD &&
test_cmp j.tgz j3.tar.gz
'

if $GUNZIP --version >/dev/null 2>&1; then
test_set_prereq GUNZIP
else
say "Skipping some tar.gz tests because gunzip was not found"
fi

test_expect_success GZIP,GUNZIP 'extract tgz file' '
$GUNZIP -c <j.tgz >j.tar &&
test_cmp b.tar j.tar
'

test_done

0 comments on commit 0e804e0

Please sign in to comment.