static int run_remote_archiver(int argc, const char **argv, const char *remote, const char *exec, const char *name_hint) { char buf[LARGE_PACKET_MAX]; int fd[2], i, len, rv; struct transport *transport; struct remote *_remote; _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); /* * Inject a fake --format field at the beginning of the * arguments, with the format inferred from our output * filename. This way explicit --format options can override * it. */ if (name_hint) { const char *format = archive_format_from_filename(name_hint); if (format) packet_write(fd[1], "argument --format=%s\n", format); } for (i = 1; i < argc; i++) packet_write(fd[1], "argument %s\n", argv[i]); packet_flush(fd[1]); len = packet_read_line(fd[0], buf, sizeof(buf)); if (!len) die(_("git archive: expected ACK/NAK, got EOF")); if (buf[len-1] == '\n') buf[--len] = 0; if (strcmp(buf, "ACK")) { if (len > 5 && !prefixcmp(buf, "NACK ")) die(_("git archive: NACK %s"), buf + 5); die(_("git archive: protocol error")); } len = packet_read_line(fd[0], buf, sizeof(buf)); if (len) die(_("git archive: expected a flush")); /* Now, start reading from fd[0] and spit it out to stdout */ rv = recv_sideband("archive", fd[0], 1); rv |= transport_disconnect(transport); return !!rv; }
static int parse_archive_args(int argc, const char **argv, const struct archiver **ar, struct archiver_args *args, const char *name_hint, int is_remote) { const char *format = NULL; const char *base = NULL; const char *remote = NULL; const char *exec = NULL; const char *output = NULL; int compression_level = -1; int verbose = 0; int i; int list = 0; int worktree_attributes = 0; struct option opts[] = { OPT_GROUP(""), OPT_STRING(0, "format", &format, N_("fmt"), N_("archive format")), OPT_STRING(0, "prefix", &base, N_("prefix"), N_("prepend prefix to each pathname in the archive")), OPT_STRING('o', "output", &output, N_("file"), N_("write the archive to this file")), OPT_BOOL(0, "worktree-attributes", &worktree_attributes, N_("read .gitattributes in working directory")), OPT__VERBOSE(&verbose, N_("report archived files on stderr")), OPT__COMPR('0', &compression_level, N_("store only"), 0), OPT__COMPR('1', &compression_level, N_("compress faster"), 1), OPT__COMPR_HIDDEN('2', &compression_level, 2), OPT__COMPR_HIDDEN('3', &compression_level, 3), OPT__COMPR_HIDDEN('4', &compression_level, 4), OPT__COMPR_HIDDEN('5', &compression_level, 5), OPT__COMPR_HIDDEN('6', &compression_level, 6), OPT__COMPR_HIDDEN('7', &compression_level, 7), OPT__COMPR_HIDDEN('8', &compression_level, 8), OPT__COMPR('9', &compression_level, N_("compress better"), 9), OPT_GROUP(""), OPT_BOOL('l', "list", &list, N_("list supported archive formats")), OPT_GROUP(""), OPT_STRING(0, "remote", &remote, N_("repo"), N_("retrieve the archive from remote repository <repo>")), OPT_STRING(0, "exec", &exec, N_("command"), N_("path to the remote git-upload-archive command")), OPT_END() }; argc = parse_options(argc, argv, NULL, opts, archive_usage, 0); if (remote) die("Unexpected option --remote"); if (exec) die("Option --exec can only be used together with --remote"); if (output) die("Unexpected option --output"); if (!base) base = ""; if (list) { for (i = 0; i < nr_archivers; i++) if (!is_remote || archivers[i]->flags & ARCHIVER_REMOTE) printf("%s\n", archivers[i]->name); exit(0); } if (!format && name_hint) format = archive_format_from_filename(name_hint); if (!format) format = "tar"; /* We need at least one parameter -- tree-ish */ if (argc < 1) usage_with_options(archive_usage, opts); *ar = lookup_archiver(format); if (!*ar || (is_remote && !((*ar)->flags & ARCHIVER_REMOTE))) die("Unknown archive format '%s'", format); args->compression_level = Z_DEFAULT_COMPRESSION; if (compression_level != -1) { if ((*ar)->flags & ARCHIVER_WANT_COMPRESSION_LEVELS) args->compression_level = compression_level; else { die("Argument not supported for format '%s': -%d", format, compression_level); } } args->verbose = verbose; args->base = base; args->baselen = strlen(base); args->worktree_attributes = worktree_attributes; return argc; }