From: Junio C Hamano Date: Sun, 7 Feb 2010 23:52:12 +0000 (-0800) Subject: Merge branch 'maint' X-Git-Tag: v1.7.0-rc2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e7ec9de67639d7c1715b450f54d297cc38e25867?ds=inline;hp=-c Merge branch 'maint' * maint: archive: simplify archive format guessing --- e7ec9de67639d7c1715b450f54d297cc38e25867 diff --combined builtin-archive.c index 3fb41364a5,faf4554d5e..6a887f5a9d --- a/builtin-archive.c +++ b/builtin-archive.c @@@ -5,7 -5,6 +5,7 @@@ #include "cache.h" #include "builtin.h" #include "archive.h" +#include "transport.h" #include "parse-options.h" #include "pkt-line.h" #include "sideband.h" @@@ -26,16 -25,12 +26,16 @@@ static void create_output_file(const ch static int run_remote_archiver(int argc, const char **argv, const char *remote, const char *exec) { - char *url, buf[LARGE_PACKET_MAX]; + char buf[LARGE_PACKET_MAX]; int fd[2], i, len, rv; - struct child_process *conn; + struct transport *transport; + struct remote *_remote; - url = xstrdup(remote); - conn = git_connect(fd, url, exec, 0); + _remote = remote_get(remote); + if (!_remote->url[0]) + die("git archive: Remote with no URL"); + transport = transport_get(_remote, _remote->url[0]); + transport_connect(transport, "git-upload-archive", exec, fd); for (i = 1; i < argc; i++) packet_write(fd[1], "argument %s\n", argv[i]); @@@ -58,7 -53,9 +58,7 @@@ /* Now, start reading from fd[0] and spit it out to stdout */ rv = recv_sideband("archive", fd[0], 1); - close(fd[0]); - close(fd[1]); - rv |= finish_connect(conn); + rv |= transport_disconnect(transport); return !!rv; } @@@ -70,7 -67,7 +70,7 @@@ static const char *format_from_name(con return NULL; ext++; if (!strcasecmp(ext, "zip")) - return "zip"; + return "--format=zip"; return NULL; } @@@ -84,7 -81,7 +84,7 @@@ int cmd_archive(int argc, const char ** 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 -89,31 +92,31 @@@ "retrieve the archive from remote repository "), 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; }