summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e804e0)
raw | patch | inline | side by side (parent: 0e804e0)
author | Jeff King <peff@github.com> | |
Wed, 22 Jun 2011 03:17:35 +0000 (23:17 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 22 Jun 2011 18:12:35 +0000 (11:12 -0700) |
Some tar filters may be very expensive to run, so sites do
not want to expose them via upload-archive. This patch lets
users configure tar.<filter>.remote to turn them off.
By default, gzip filters are left on, as they are about as
expensive as creating zip archives.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
not want to expose them via upload-archive. This patch lets
users configure tar.<filter>.remote to turn them off.
By default, gzip filters are left on, as they are about as
expensive as creating zip archives.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index 8b0080a97759314e7b5f9c0c404c4e7d4af0a401..1320c873ad61281ef33891170da8683dc785f011 100644 (file)
The "tar.gz" and "tgz" formats are defined automatically and default to
`gzip -cn`. You may override them with custom commands.
+tar.<format>.remote::
+ If true, enable `<format>` for use by remote clients via
+ linkgit:git-upload-archive[1]. Defaults to false for
+ user-defined formats, but true for the "tar.gz" and "tgz"
+ formats.
+
ATTRIBUTES
----------
diff --git a/archive-tar.c b/archive-tar.c
index f470ebea1240dd48c6b34e88912a1f24137d3742..20af0051a334a1357b055ea10d74f5380117ab68 100644 (file)
--- a/archive-tar.c
+++ b/archive-tar.c
ar->data = xstrdup(value);
return 0;
}
+ if (!strcmp(type, "remote")) {
+ if (git_config_bool(var, value))
+ ar->flags |= ARCHIVER_REMOTE;
+ else
+ ar->flags &= ~ARCHIVER_REMOTE;
+ return 0;
+ }
return 0;
}
static struct archiver tar_archiver = {
"tar",
write_tar_archive,
- 0
+ ARCHIVER_REMOTE
};
void init_tar_archiver(void)
register_archiver(&tar_archiver);
tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
+ tar_filter_config("tar.tgz.remote", "true", NULL);
tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
+ tar_filter_config("tar.tar.gz.remote", "true", NULL);
git_config(git_tar_config, NULL);
for (i = 0; i < nr_tar_filters; i++) {
/* omit any filters that never had a command configured */
diff --git a/archive-zip.c b/archive-zip.c
index 42df66080acad9a6705227a075058246e12078b2..3c102a1648304552ff24f8a7fad92b2fc35bba01 100644 (file)
--- a/archive-zip.c
+++ b/archive-zip.c
static struct archiver zip_archiver = {
"zip",
write_zip_archive,
- ARCHIVER_WANT_COMPRESSION_LEVELS
+ ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
};
void init_zip_archiver(void)
diff --git a/archive.c b/archive.c
index 41065a8e2c8362b95c039b7493f842f791f6858b..2a7a28e3ed35fe9db03ccf70b71867f7f8a22b8e 100644 (file)
--- a/archive.c
+++ b/archive.c
static int parse_archive_args(int argc, const char **argv,
const struct archiver **ar, struct archiver_args *args,
- const char *name_hint)
+ const char *name_hint, int is_remote)
{
const char *format = NULL;
const char *base = NULL;
if (list) {
for (i = 0; i < nr_archivers; i++)
- printf("%s\n", archivers[i]->name);
+ if (!is_remote || archivers[i]->flags & ARCHIVER_REMOTE)
+ printf("%s\n", archivers[i]->name);
exit(0);
}
if (argc < 1)
usage_with_options(archive_usage, opts);
*ar = lookup_archiver(format);
- if (!*ar)
+ if (!*ar || (is_remote && !((*ar)->flags & ARCHIVER_REMOTE)))
die("Unknown archive format '%s'", format);
args->compression_level = Z_DEFAULT_COMPRESSION;
}
int write_archive(int argc, const char **argv, const char *prefix,
- int setup_prefix, const char *name_hint)
+ int setup_prefix, const char *name_hint, int remote)
{
int nongit = 0;
const struct archiver *ar = NULL;
init_tar_archiver();
init_zip_archiver();
- argc = parse_archive_args(argc, argv, &ar, &args, name_hint);
+ argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
if (nongit) {
/*
* We know this will die() with an error, so we could just
diff --git a/archive.h b/archive.h
index 202d528728415565a2628fc2cf1b3232a8d10c78..2b0884f1ef3123f26d9a7b3ba03e3d14ae1ccd57 100644 (file)
--- a/archive.h
+++ b/archive.h
};
#define ARCHIVER_WANT_COMPRESSION_LEVELS 1
+#define ARCHIVER_REMOTE 2
struct archiver {
const char *name;
int (*write_archive)(const struct archiver *, struct archiver_args *);
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args, const unsigned char *sha1, const char *path, size_t pathlen, unsigned int mode, void *buffer, unsigned long size);
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
-extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint);
+extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint, int remote);
const char *archive_format_from_filename(const char *filename);
diff --git a/builtin/archive.c b/builtin/archive.c
index 2578cf57f0d80f0daef2e49b6c0baf3c3df5390a..883c0092ad43d602136e68d2afde8e319a904676 100644 (file)
--- a/builtin/archive.c
+++ b/builtin/archive.c
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
- return write_archive(argc, argv, prefix, 1, output);
+ return write_archive(argc, argv, prefix, 1, output, 0);
}
index e6bb97d3455bae2aa3b1104c0f46fc8bd9fa7bdd..2d0b38333eadef0a5c6501e5a3046ebc2afa048e 100644 (file)
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
sent_argv[sent_argc] = NULL;
/* parse all options sent by the client */
- return write_archive(sent_argc, sent_argv, prefix, 0, NULL);
+ return write_archive(sent_argc, sent_argv, prefix, 0, NULL, 1);
}
__attribute__((format (printf, 1, 2)))
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 070250ebb0cb2b59560e63a56847dcd947b0d54a..9e3ba98fc8d6f0242af38c3f7dc062e6c6ab9604 100755 (executable)
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
test_expect_success 'setup tar filters' '
git config tar.tar.foo.command "tr ab ba" &&
- git config tar.bar.command "tr ab ba"
+ git config tar.bar.command "tr ab ba" &&
+ git config tar.bar.remote true
'
test_expect_success 'archive --list mentions user filter' '
grep "^bar\$" output
'
-test_expect_success 'archive --list shows remote user filters' '
+test_expect_success 'archive --list shows only enabled remote filters' '
git archive --list --remote=. >output &&
- grep "^tar\.foo\$" output &&
+ ! grep "^tar\.foo\$" output &&
grep "^bar\$" output
'
test_cmp b.tar config-implicittar.foo
'
+test_expect_success 'only enabled filters are available remotely' '
+ test_must_fail git archive --remote=. --format=tar.foo HEAD \
+ >remote.tar.foo &&
+ git archive --remote=. --format=bar >remote.bar HEAD &&
+ test_cmp remote.bar config.bar
+'
+
if $GZIP --version >/dev/null 2>&1; then
test_set_prereq GZIP
else
test_cmp b.tar j.tar
'
+test_expect_success GZIP 'remote tar.gz is allowed by default' '
+ git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
+ test_cmp j.tgz remote.tar.gz
+'
+
+test_expect_success GZIP 'remote tar.gz can be disabled' '
+ git config tar.tar.gz.remote false &&
+ test_must_fail git archive --remote=. --format=tar.gz HEAD \
+ >remote.tar.gz
+'
+
test_done