[PATCH 7/7] archive: provide builtin .tar.gz filter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This works exactly as if the user had configured it via:

  [tarfilter "tgz"]
	command = gzip
	extension = tgz
	extension = tar.gz
	compressionlevels = true

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@xxxxxxxx>
---
 archive-tar-filter.c |   12 ++++++++++++
 t/t5000-tar-tree.sh  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/archive-tar-filter.c b/archive-tar-filter.c
index e749133..de8719a 100644
--- a/archive-tar-filter.c
+++ b/archive-tar-filter.c
@@ -126,6 +126,17 @@ static void remove_filters_without_command(void)
 	}
 }
 
+static void load_builtin_filters(void)
+{
+	struct tar_filter *tf;
+
+	tf = tar_filter_new("tgz", strlen("tgz"));
+	tf->command = xstrdup("gzip");
+	string_list_append(&tf->extensions, "tgz");
+	string_list_append(&tf->extensions, "tar.gz");
+	tf->use_compression = 1;
+}
+
 /*
  * We don't want to load twice, since some of our
  * values actually append rather than overwrite.
@@ -137,6 +148,7 @@ extern void tar_filter_load_config(void)
 		return;
 	tar_filter_config_loaded = 1;
 
+	load_builtin_filters();
 	git_config(tar_filter_config, NULL);
 	remove_filters_without_command();
 }
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index fe661f3..ebad295 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -26,6 +26,7 @@ commit id embedding:
 
 . ./test-lib.sh
 UNZIP=${UNZIP:-unzip}
+GUNZIP=${GUNZIP:-gzip -d}
 
 SUBSTFORMAT=%H%n
 
@@ -306,4 +307,51 @@ test_expect_success 'extension matching requires dot' '
 	test_cmp b.tar config-implicittar.foo
 '
 
+test_expect_success 'git archive --format=tgz' '
+	git archive --format=tgz HEAD >j.tgz
+'
+
+test_expect_success 'infer tgz from .tgz filename' '
+	git archive --output=j1.tgz HEAD &&
+	test_cmp j.tgz j1.tgz
+'
+
+test_expect_success 'infer tgz from .tar.gz filename' '
+	git archive --output=j2.tar.gz HEAD &&
+	test_cmp j.tgz j2.tar.gz
+'
+
+if $GUNZIP --version >/dev/null 2>&1; then
+	test_set_prereq GUNZIP
+else
+	say "Skipping some tgz tests because gunzip was not found"
+fi
+
+test_expect_success GUNZIP 'extract tgz file' '
+	$GUNZIP -c <j.tgz >j.tar &&
+	test_cmp b.tar j.tar
+'
+
+test_expect_success GUNZIP 'tgz allows compression levels' '
+	git archive -1 --output=j3.tgz HEAD
+'
+
+test_expect_success 'disable builtin tgz via config' '
+	git config tarfilter.tgz.command ""
+'
+
+test_expect_success 'disabled filter does not appear in --list' '
+	git archive --list >output &&
+	! grep tgz output
+'
+
+test_expect_success 'disabled filter cannot be used' '
+	test_must_fail git archive --format=tgz HEAD >output
+'
+
+test_expect_success 'disabled filter does not match extensions' '
+	git archive -o disabled.tar.gz HEAD &&
+	test_cmp b.tar disabled.tar.gz
+'
+
 test_done
-- 
1.7.6.rc1.4.g49204
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]