diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-02-07 15:52:12 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-02-07 15:52:12 -0800 |
commit | e7ec9de67639d7c1715b450f54d297cc38e25867 (patch) | |
tree | 2cd108fb5e3e836f39872a52d810a84b43f2bcf7 | |
parent | Fix invalid read in quote_c_style_counted (diff) | |
parent | archive: simplify archive format guessing (diff) | |
download | tgif-e7ec9de67639d7c1715b450f54d297cc38e25867.tar.xz |
Merge branch 'maint'
* maint:
archive: simplify archive format guessing
-rw-r--r-- | builtin-archive.c | 34 | ||||
-rwxr-xr-x | t/t5000-tar-tree.sh | 10 |
2 files changed, 26 insertions, 18 deletions
diff --git a/builtin-archive.c b/builtin-archive.c index 3fb41364a5..6a887f5a9d 100644 --- a/builtin-archive.c +++ b/builtin-archive.c @@ -70,7 +70,7 @@ static const char *format_from_name(const char *filename) return NULL; ext++; if (!strcasecmp(ext, "zip")) - return "zip"; + return "--format=zip"; return NULL; } @@ -84,7 +84,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix) const char *exec = "git-upload-archive"; const char *output = NULL; const char *remote = NULL; - const char *format = NULL; + const char *format_option = NULL; struct option local_opts[] = { OPT_STRING('o', "output", &output, "file", "write the archive to this file"), @@ -92,33 +92,31 @@ int cmd_archive(int argc, const char **argv, const char *prefix) "retrieve the archive from remote repository <repo>"), OPT_STRING(0, "exec", &exec, "cmd", "path to the remote git-upload-archive command"), - OPT_STRING(0, "format", &format, "fmt", "archive format"), OPT_END() }; - char fmt_opt[32]; argc = parse_options(argc, argv, prefix, local_opts, NULL, PARSE_OPT_KEEP_ALL); if (output) { create_output_file(output); - if (!format) - format = format_from_name(output); + format_option = format_from_name(output); } - if (format) { - sprintf(fmt_opt, "--format=%s", format); - /* - * We have enough room in argv[] to muck it in place, - * because either --format and/or --output must have - * been given on the original command line if we get - * to this point, and parse_options() must have eaten - * it, i.e. we can add back one element to the array. - * But argv[] may contain "--"; we should make it the - * first option. - */ + /* + * We have enough room in argv[] to muck it in place, because + * --output must have been given on the original command line + * if we get to this point, and parse_options() must have eaten + * it, i.e. we can add back one element to the array. + * + * We add a fake --format option at the beginning, with the + * format inferred from our output filename. This way explicit + * --format options can override it, and the fake option is + * inserted before any "--" that might have been given. + */ + if (format_option) { memmove(argv + 2, argv + 1, sizeof(*argv) * argc); - argv[1] = fmt_opt; + argv[1] = format_option; argv[++argc] = NULL; } diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 0037f63d91..27bfba55bd 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -189,6 +189,16 @@ test_expect_success 'git archive --format=zip with --output' \ 'git archive --format=zip --output=d2.zip HEAD && test_cmp d.zip d2.zip' +test_expect_success 'git archive with --output, inferring format' ' + git archive --output=d3.zip HEAD && + test_cmp d.zip d3.zip +' + +test_expect_success 'git archive with --output, override inferred format' ' + git archive --format=tar --output=d4.zip HEAD && + test_cmp b.tar d4.zip +' + $UNZIP -v >/dev/null 2>&1 if [ $? -eq 127 ]; then say "Skipping ZIP tests, because unzip was not found" |