upload-archive: allow user to turn off filters
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>
Jeff King committed
Jun 21, 2011 at 23:17 UTC
7b97730b764cac823531ccd14669f9c5b45496dc
8 files changed
+49
-13
Documentation/git-archive.txt
+6
@@ -114,6 +114,12 @@ tar.<format>.command::
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
+tar.<format>.remote::
118
+ If true, enable `<format>` for use by remote clients via
119
+ linkgit:git-upload-archive[1]. Defaults to false for
120
+ user-defined formats, but true for the "tar.gz" and "tgz"
121
+ formats.
122
+
123
ATTRIBUTES
124
----------
125
archive-tar.c
+10
-1
@@ -274,6 +274,13 @@ static int tar_filter_config(const char *var, const char *value, void *data)
274
ar->data = xstrdup(value);
275
return 0;
276
}
277
+ if (!strcmp(type, "remote")) {
278
+ if (git_config_bool(var, value))
279
+ ar->flags |= ARCHIVER_REMOTE;
280
+ else
281
+ ar->flags &= ~ARCHIVER_REMOTE;
282
+ return 0;
283
+ }
284
285
return 0;
286
}
@@ -349,7 +356,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
356
static struct archiver tar_archiver = {
357
"tar",
358
write_tar_archive,
352
- 0
359
+ ARCHIVER_REMOTE
360
};
361
362
void init_tar_archiver(void)
@@ -358,7 +365,9 @@ void init_tar_archiver(void)
365
register_archiver(&tar_archiver);
366
367
tar_filter_config("tar.tgz.command", "gzip -cn", NULL);
368
+ tar_filter_config("tar.tgz.remote", "true", NULL);
369
tar_filter_config("tar.tar.gz.command", "gzip -cn", NULL);
370
+ tar_filter_config("tar.tar.gz.remote", "true", NULL);
371
git_config(git_tar_config, NULL);
372
for (i = 0; i < nr_tar_filters; i++) {
373
/* omit any filters that never had a command configured */
archive-zip.c
+1
-1
@@ -283,7 +283,7 @@ static int write_zip_archive(const struct archiver *ar,
283
static struct archiver zip_archiver = {
284
"zip",
285
write_zip_archive,
286
- ARCHIVER_WANT_COMPRESSION_LEVELS
286
+ ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
287
};
288
289
void init_zip_archiver(void)
archive.c
+6
-5
@@ -299,7 +299,7 @@ static void parse_treeish_arg(const char **argv,
299
300
static int parse_archive_args(int argc, const char **argv,
301
const struct archiver **ar, struct archiver_args *args,
302
- const char *name_hint)
302
+ const char *name_hint, int is_remote)
303
{
304
const char *format = NULL;
305
const char *base = NULL;
@@ -356,7 +356,8 @@ static int parse_archive_args(int argc, const char **argv,
356
357
if (list) {
358
for (i = 0; i < nr_archivers; i++)
359
- printf("%s\n", archivers[i]->name);
359
+ if (!is_remote || archivers[i]->flags & ARCHIVER_REMOTE)
360
+ printf("%s\n", archivers[i]->name);
361
exit(0);
362
}
363
@@ -369,7 +370,7 @@ static int parse_archive_args(int argc, const char **argv,
370
if (argc < 1)
371
usage_with_options(archive_usage, opts);
372
*ar = lookup_archiver(format);
372
- if (!*ar)
373
+ if (!*ar || (is_remote && !((*ar)->flags & ARCHIVER_REMOTE)))
374
die("Unknown archive format '%s'", format);
375
376
args->compression_level = Z_DEFAULT_COMPRESSION;
@@ -390,7 +391,7 @@ static int parse_archive_args(int argc, const char **argv,
391
}
392
393
int write_archive(int argc, const char **argv, const char *prefix,
393
- int setup_prefix, const char *name_hint)
394
+ int setup_prefix, const char *name_hint, int remote)
395
{
396
int nongit = 0;
397
const struct archiver *ar = NULL;
@@ -403,7 +404,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
404
init_tar_archiver();
405
init_zip_archiver();
406
406
- argc = parse_archive_args(argc, argv, &ar, &args, name_hint);
407
+ argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
408
if (nongit) {
409
/*
410
* We know this will die() with an error, so we could just
archive.h
+2
-1
@@ -15,6 +15,7 @@ struct archiver_args {
15
};
16
17
#define ARCHIVER_WANT_COMPRESSION_LEVELS 1
18
+#define ARCHIVER_REMOTE 2
19
struct archiver {
20
const char *name;
21
int (*write_archive)(const struct archiver *, struct archiver_args *);
@@ -29,7 +30,7 @@ extern void init_zip_archiver(void);
30
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);
31
32
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
32
-extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint);
33
+extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint, int remote);
34
35
const char *archive_format_from_filename(const char *filename);
36
builtin/archive.c
+1
-1
@@ -106,5 +106,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
106
107
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
108
109
- return write_archive(argc, argv, prefix, 1, output);
109
+ return write_archive(argc, argv, prefix, 1, output, 0);
110
}
builtin/upload-archive.c
+1
-1
@@ -64,7 +64,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix)
64
sent_argv[sent_argc] = NULL;
65
66
/* parse all options sent by the client */
67
- return write_archive(sent_argc, sent_argv, prefix, 0, NULL);
67
+ return write_archive(sent_argc, sent_argv, prefix, 0, NULL, 1);
68
}
69
70
__attribute__((format (printf, 1, 2)))
t/t5000-tar-tree.sh
+22
-3
@@ -256,7 +256,8 @@ test_expect_success 'git-archive --prefix=olde-' '
256
257
test_expect_success 'setup tar filters' '
258
git config tar.tar.foo.command "tr ab ba" &&
259
- git config tar.bar.command "tr ab ba"
259
+ git config tar.bar.command "tr ab ba" &&
260
+ git config tar.bar.remote true
261
'
262
263
test_expect_success 'archive --list mentions user filter' '
@@ -265,9 +266,9 @@ test_expect_success 'archive --list mentions user filter' '
266
grep "^bar\$" output
267
'
268
268
-test_expect_success 'archive --list shows remote user filters' '
269
+test_expect_success 'archive --list shows only enabled remote filters' '
270
git archive --list --remote=. >output &&
270
- grep "^tar\.foo\$" output &&
271
+ ! grep "^tar\.foo\$" output &&
272
grep "^bar\$" output
273
'
274
@@ -297,6 +298,13 @@ test_expect_success 'extension matching requires dot' '
298
test_cmp b.tar config-implicittar.foo
299
'
300
301
+test_expect_success 'only enabled filters are available remotely' '
302
+ test_must_fail git archive --remote=. --format=tar.foo HEAD \
303
+ >remote.tar.foo &&
304
+ git archive --remote=. --format=bar >remote.bar HEAD &&
305
+ test_cmp remote.bar config.bar
306
+'
307
+
308
if $GZIP --version >/dev/null 2>&1; then
309
test_set_prereq GZIP
310
else
@@ -333,4 +341,15 @@ test_expect_success GZIP,GUNZIP 'extract tgz file' '
341
test_cmp b.tar j.tar
342
'
343
344
+test_expect_success GZIP 'remote tar.gz is allowed by default' '
345
+ git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
346
+ test_cmp j.tgz remote.tar.gz
347
+'
348
+
349
+test_expect_success GZIP 'remote tar.gz can be disabled' '
350
+ git config tar.tar.gz.remote false &&
351
+ test_must_fail git archive --remote=. --format=tar.gz HEAD \
352
+ >remote.tar.gz
353
+'
354
+
355
test_done