summaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c363
1 files changed, 278 insertions, 85 deletions
diff --git a/connect.c b/connect.c
index 23013c6..0d77737 100644
--- a/connect.c
+++ b/connect.c
@@ -1,6 +1,8 @@
#include "git-compat-util.h"
-#include "cache.h"
#include "config.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
#include "pkt-line.h"
#include "quote.h"
#include "refs.h"
@@ -10,15 +12,18 @@
#include "url.h"
#include "string-list.h"
#include "oid-array.h"
+#include "path.h"
#include "transport.h"
+#include "trace2.h"
#include "strbuf.h"
#include "version.h"
#include "protocol.h"
#include "alias.h"
+#include "bundle-uri.h"
static char *server_capabilities_v1;
-static struct argv_array server_capabilities_v2 = ARGV_ARRAY_INIT;
-static const char *parse_feature_value(const char *, const char *, int *);
+static struct strvec server_capabilities_v2 = STRVEC_INIT;
+static const char *next_server_feature_value(const char *feature, size_t *len, size_t *offset);
static int check_ref(const char *name, unsigned int flags)
{
@@ -29,7 +34,8 @@ static int check_ref(const char *name, unsigned int flags)
return 0;
/* REF_NORMAL means that we don't want the magic fake tag refs */
- if ((flags & REF_NORMAL) && check_refname_format(name, 0))
+ if ((flags & REF_NORMAL) && check_refname_format(name,
+ REFNAME_ALLOW_ONELEVEL))
return 0;
/* REF_HEADS means that we want regular branch heads */
@@ -66,20 +72,37 @@ static NORETURN void die_initial_contact(int unexpected)
}
/* Checks if the server supports the capability 'c' */
-int server_supports_v2(const char *c, int die_on_error)
+int server_supports_v2(const char *c)
{
int i;
- for (i = 0; i < server_capabilities_v2.argc; i++) {
+ for (i = 0; i < server_capabilities_v2.nr; i++) {
const char *out;
- if (skip_prefix(server_capabilities_v2.argv[i], c, &out) &&
+ if (skip_prefix(server_capabilities_v2.v[i], c, &out) &&
(!*out || *out == '='))
return 1;
}
+ return 0;
+}
- if (die_on_error)
+void ensure_server_supports_v2(const char *c)
+{
+ if (!server_supports_v2(c))
die(_("server doesn't support '%s'"), c);
+}
+int server_feature_v2(const char *c, const char **v)
+{
+ int i;
+
+ for (i = 0; i < server_capabilities_v2.nr; i++) {
+ const char *out;
+ if (skip_prefix(server_capabilities_v2.v[i], c, &out) &&
+ (*out == '=')) {
+ *v = out + 1;
+ return 1;
+ }
+ }
return 0;
}
@@ -88,9 +111,9 @@ int server_supports_feature(const char *c, const char *feature,
{
int i;
- for (i = 0; i < server_capabilities_v2.argc; i++) {
+ for (i = 0; i < server_capabilities_v2.nr; i++) {
const char *out;
- if (skip_prefix(server_capabilities_v2.argv[i], c, &out) &&
+ if (skip_prefix(server_capabilities_v2.v[i], c, &out) &&
(!*out || *(out++) == '=')) {
if (parse_feature_request(out, feature))
return 1;
@@ -108,7 +131,7 @@ int server_supports_feature(const char *c, const char *feature,
static void process_capabilities_v2(struct packet_reader *reader)
{
while (packet_reader_read(reader) == PACKET_READ_NORMAL)
- argv_array_push(&server_capabilities_v2, reader->line);
+ strvec_push(&server_capabilities_v2, reader->line);
if (reader->status != PACKET_READ_FLUSH)
die(_("expected flush after capabilities"));
@@ -127,6 +150,7 @@ enum protocol_version discover_version(struct packet_reader *reader)
die_initial_contact(0);
case PACKET_READ_FLUSH:
case PACKET_READ_DELIM:
+ case PACKET_READ_RESPONSE_END:
version = protocol_v0;
break;
case PACKET_READ_NORMAL:
@@ -148,6 +172,8 @@ enum protocol_version discover_version(struct packet_reader *reader)
BUG("unknown protocol version");
}
+ trace2_data_intmax("transfer", NULL, "negotiated-version", version);
+
return version;
}
@@ -180,17 +206,16 @@ reject:
static void annotate_refs_with_symref_info(struct ref *ref)
{
struct string_list symref = STRING_LIST_INIT_DUP;
- const char *feature_list = server_capabilities_v1;
+ size_t offset = 0;
- while (feature_list) {
- int len;
+ while (1) {
+ size_t len;
const char *val;
- val = parse_feature_value(feature_list, "symref", &len);
+ val = next_server_feature_value("symref", &len, &offset);
if (!val)
break;
parse_one_symref_info(&symref, val, len);
- feature_list = val + 1;
}
string_list_sort(&symref);
@@ -204,27 +229,43 @@ static void annotate_refs_with_symref_info(struct ref *ref)
string_list_clear(&symref, 0);
}
-static void process_capabilities(const char *line, int *len)
+static void process_capabilities(struct packet_reader *reader, int *linelen)
{
+ const char *feat_val;
+ size_t feat_len;
+ const char *line = reader->line;
int nul_location = strlen(line);
- if (nul_location == *len)
+ if (nul_location == *linelen)
return;
server_capabilities_v1 = xstrdup(line + nul_location + 1);
- *len = nul_location;
+ *linelen = nul_location;
+
+ feat_val = server_feature_value("object-format", &feat_len);
+ if (feat_val) {
+ char *hash_name = xstrndup(feat_val, feat_len);
+ int hash_algo = hash_algo_by_name(hash_name);
+ if (hash_algo != GIT_HASH_UNKNOWN)
+ reader->hash_algo = &hash_algos[hash_algo];
+ free(hash_name);
+ } else {
+ reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
+ }
}
-static int process_dummy_ref(const char *line)
+static int process_dummy_ref(const struct packet_reader *reader)
{
+ const char *line = reader->line;
struct object_id oid;
const char *name;
- if (parse_oid_hex(line, &oid, &name))
+ if (parse_oid_hex_algop(line, &oid, &name, reader->hash_algo))
return 0;
if (*name != ' ')
return 0;
name++;
- return oideq(&null_oid, &oid) && !strcmp(name, "capabilities^{}");
+ return oideq(reader->hash_algo->null_oid, &oid) &&
+ !strcmp(name, "capabilities^{}");
}
static void check_no_capabilities(const char *line, int len)
@@ -234,13 +275,15 @@ static void check_no_capabilities(const char *line, int len)
line + strlen(line));
}
-static int process_ref(const char *line, int len, struct ref ***list,
- unsigned int flags, struct oid_array *extra_have)
+static int process_ref(const struct packet_reader *reader, int len,
+ struct ref ***list, unsigned int flags,
+ struct oid_array *extra_have)
{
+ const char *line = reader->line;
struct object_id old_oid;
const char *name;
- if (parse_oid_hex(line, &old_oid, &name))
+ if (parse_oid_hex_algop(line, &old_oid, &name, reader->hash_algo))
return 0;
if (*name != ' ')
return 0;
@@ -260,16 +303,17 @@ static int process_ref(const char *line, int len, struct ref ***list,
return 1;
}
-static int process_shallow(const char *line, int len,
+static int process_shallow(const struct packet_reader *reader, int len,
struct oid_array *shallow_points)
{
+ const char *line = reader->line;
const char *arg;
struct object_id old_oid;
if (!skip_prefix(line, "shallow ", &arg))
return 0;
- if (get_oid_hex(arg, &old_oid))
+ if (get_oid_hex_algop(arg, &old_oid, reader->hash_algo))
die(_("protocol error: expected shallow sha-1, got '%s'"), arg);
if (!shallow_points)
die(_("repository on the other end cannot be shallow"));
@@ -310,25 +354,26 @@ struct ref **get_remote_heads(struct packet_reader *reader,
state = EXPECTING_DONE;
break;
case PACKET_READ_DELIM:
+ case PACKET_READ_RESPONSE_END:
die(_("invalid packet"));
}
switch (state) {
case EXPECTING_FIRST_REF:
- process_capabilities(reader->line, &len);
- if (process_dummy_ref(reader->line)) {
+ process_capabilities(reader, &len);
+ if (process_dummy_ref(reader)) {
state = EXPECTING_SHALLOW;
break;
}
state = EXPECTING_REF;
/* fallthrough */
case EXPECTING_REF:
- if (process_ref(reader->line, len, &list, flags, extra_have))
+ if (process_ref(reader, len, &list, flags, extra_have))
break;
state = EXPECTING_SHALLOW;
/* fallthrough */
case EXPECTING_SHALLOW:
- if (process_shallow(reader->line, len, shallow_points))
+ if (process_shallow(reader, len, shallow_points))
break;
die(_("protocol error: unexpected '%s'"), reader->line);
case EXPECTING_DONE:
@@ -342,7 +387,8 @@ struct ref **get_remote_heads(struct packet_reader *reader,
}
/* Returns 1 when a valid ref has been added to `list`, 0 otherwise */
-static int process_ref_v2(const char *line, struct ref ***list)
+static int process_ref_v2(struct packet_reader *reader, struct ref ***list,
+ const char **unborn_head_target)
{
int ret = 1;
int i = 0;
@@ -350,6 +396,7 @@ static int process_ref_v2(const char *line, struct ref ***list)
struct ref *ref;
struct string_list line_sections = STRING_LIST_INIT_DUP;
const char *end;
+ const char *line = reader->line;
/*
* Ref lines have a number of fields which are space deliminated. The
@@ -362,7 +409,26 @@ static int process_ref_v2(const char *line, struct ref ***list)
goto out;
}
- if (parse_oid_hex(line_sections.items[i++].string, &old_oid, &end) ||
+ if (!strcmp("unborn", line_sections.items[i].string)) {
+ i++;
+ if (unborn_head_target &&
+ !strcmp("HEAD", line_sections.items[i++].string)) {
+ /*
+ * Look for the symref target (if any). If found,
+ * return it to the caller.
+ */
+ for (; i < line_sections.nr; i++) {
+ const char *arg = line_sections.items[i].string;
+
+ if (skip_prefix(arg, "symref-target:", &arg)) {
+ *unborn_head_target = xstrdup(arg);
+ break;
+ }
+ }
+ }
+ goto out;
+ }
+ if (parse_oid_hex_algop(line_sections.items[i++].string, &old_oid, &end, reader->hash_algo) ||
*end) {
ret = 0;
goto out;
@@ -370,7 +436,7 @@ static int process_ref_v2(const char *line, struct ref ***list)
ref = alloc_ref(line_sections.items[i++].string);
- oidcpy(&ref->old_oid, &old_oid);
+ memcpy(ref->old_oid.hash, old_oid.hash, reader->hash_algo->rawsz);
**list = ref;
*list = &ref->next;
@@ -383,7 +449,8 @@ static int process_ref_v2(const char *line, struct ref ***list)
struct object_id peeled_oid;
char *peeled_name;
struct ref *peeled;
- if (parse_oid_hex(arg, &peeled_oid, &end) || *end) {
+ if (parse_oid_hex_algop(arg, &peeled_oid, &end,
+ reader->hash_algo) || *end) {
ret = 0;
goto out;
}
@@ -391,7 +458,8 @@ static int process_ref_v2(const char *line, struct ref ***list)
peeled_name = xstrfmt("%s^{}", ref->name);
peeled = alloc_ref(peeled_name);
- oidcpy(&peeled->old_oid, &peeled_oid);
+ memcpy(peeled->old_oid.hash, peeled_oid.hash,
+ reader->hash_algo->rawsz);
**list = peeled;
*list = &peeled->next;
@@ -404,57 +472,142 @@ out:
return ret;
}
+void check_stateless_delimiter(int stateless_rpc,
+ struct packet_reader *reader,
+ const char *error)
+{
+ if (!stateless_rpc)
+ return; /* not in stateless mode, no delimiter expected */
+ if (packet_reader_read(reader) != PACKET_READ_RESPONSE_END)
+ die("%s", error);
+}
+
+static void send_capabilities(int fd_out, struct packet_reader *reader)
+{
+ const char *hash_name;
+
+ if (server_supports_v2("agent"))
+ packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized());
+
+ if (server_feature_v2("object-format", &hash_name)) {
+ int hash_algo = hash_algo_by_name(hash_name);
+ if (hash_algo == GIT_HASH_UNKNOWN)
+ die(_("unknown object format '%s' specified by server"), hash_name);
+ reader->hash_algo = &hash_algos[hash_algo];
+ packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name);
+ } else {
+ reader->hash_algo = &hash_algos[GIT_HASH_SHA1];
+ }
+}
+
+int get_remote_bundle_uri(int fd_out, struct packet_reader *reader,
+ struct bundle_list *bundles, int stateless_rpc)
+{
+ int line_nr = 1;
+
+ /* Assert bundle-uri support */
+ ensure_server_supports_v2("bundle-uri");
+
+ /* (Re-)send capabilities */
+ send_capabilities(fd_out, reader);
+
+ /* Send command */
+ packet_write_fmt(fd_out, "command=bundle-uri\n");
+ packet_delim(fd_out);
+
+ packet_flush(fd_out);
+
+ /* Process response from server */
+ while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
+ const char *line = reader->line;
+ line_nr++;
+
+ if (!bundle_uri_parse_line(bundles, line))
+ continue;
+
+ return error(_("error on bundle-uri response line %d: %s"),
+ line_nr, line);
+ }
+
+ if (reader->status != PACKET_READ_FLUSH)
+ return error(_("expected flush after bundle-uri listing"));
+
+ /*
+ * Might die(), but obscure enough that that's OK, e.g. in
+ * serve.c we'll call BUG() on its equivalent (the
+ * PACKET_READ_RESPONSE_END check).
+ */
+ check_stateless_delimiter(stateless_rpc, reader,
+ _("expected response end packet after ref listing"));
+
+ return 0;
+}
+
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
struct ref **list, int for_push,
- const struct argv_array *ref_prefixes,
- const struct string_list *server_options)
+ struct transport_ls_refs_options *transport_options,
+ const struct string_list *server_options,
+ int stateless_rpc)
{
int i;
+ struct strvec *ref_prefixes = transport_options ?
+ &transport_options->ref_prefixes : NULL;
+ const char **unborn_head_target = transport_options ?
+ &transport_options->unborn_head_target : NULL;
*list = NULL;
- if (server_supports_v2("ls-refs", 1))
- packet_write_fmt(fd_out, "command=ls-refs\n");
+ ensure_server_supports_v2("ls-refs");
+ packet_write_fmt(fd_out, "command=ls-refs\n");
- if (server_supports_v2("agent", 0))
- packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized());
+ /* Send capabilities */
+ send_capabilities(fd_out, reader);
- if (server_options && server_options->nr &&
- server_supports_v2("server-option", 1))
+ if (server_options && server_options->nr) {
+ ensure_server_supports_v2("server-option");
for (i = 0; i < server_options->nr; i++)
packet_write_fmt(fd_out, "server-option=%s",
server_options->items[i].string);
+ }
packet_delim(fd_out);
/* When pushing we don't want to request the peeled tags */
if (!for_push)
packet_write_fmt(fd_out, "peel\n");
packet_write_fmt(fd_out, "symrefs\n");
- for (i = 0; ref_prefixes && i < ref_prefixes->argc; i++) {
+ if (server_supports_feature("ls-refs", "unborn", 0))
+ packet_write_fmt(fd_out, "unborn\n");
+ for (i = 0; ref_prefixes && i < ref_prefixes->nr; i++) {
packet_write_fmt(fd_out, "ref-prefix %s\n",
- ref_prefixes->argv[i]);
+ ref_prefixes->v[i]);
}
packet_flush(fd_out);
/* Process response from server */
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
- if (!process_ref_v2(reader->line, &list))
+ if (!process_ref_v2(reader, &list, unborn_head_target))
die(_("invalid ls-refs response: %s"), reader->line);
}
if (reader->status != PACKET_READ_FLUSH)
die(_("expected flush after ref listing"));
+ check_stateless_delimiter(stateless_rpc, reader,
+ _("expected response end packet after ref listing"));
+
return list;
}
-static const char *parse_feature_value(const char *feature_list, const char *feature, int *lenp)
+const char *parse_feature_value(const char *feature_list, const char *feature, size_t *lenp, size_t *offset)
{
- int len;
+ const char *orig_start = feature_list;
+ size_t len;
if (!feature_list)
return NULL;
len = strlen(feature);
+ if (offset)
+ feature_list += *offset;
while (*feature_list) {
const char *found = strstr(feature_list, feature);
if (!found)
@@ -465,13 +618,20 @@ static const char *parse_feature_value(const char *feature_list, const char *fea
if (!*value || isspace(*value)) {
if (lenp)
*lenp = 0;
+ if (offset)
+ *offset = found + len - orig_start;
return value;
}
/* feature with a value (e.g., "agent=git/1.2.3") */
else if (*value == '=') {
+ size_t end;
+
value++;
+ end = strcspn(value, " \t\n");
if (lenp)
- *lenp = strcspn(value, " \t\n");
+ *lenp = end;
+ if (offset)
+ *offset = value + end - orig_start;
return value;
}
/*
@@ -484,14 +644,41 @@ static const char *parse_feature_value(const char *feature_list, const char *fea
return NULL;
}
+int server_supports_hash(const char *desired, int *feature_supported)
+{
+ size_t offset = 0;
+ size_t len;
+ const char *hash;
+
+ hash = next_server_feature_value("object-format", &len, &offset);
+ if (feature_supported)
+ *feature_supported = !!hash;
+ if (!hash) {
+ hash = hash_algos[GIT_HASH_SHA1].name;
+ len = strlen(hash);
+ }
+ while (hash) {
+ if (!xstrncmpz(desired, hash, len))
+ return 1;
+
+ hash = next_server_feature_value("object-format", &len, &offset);
+ }
+ return 0;
+}
+
int parse_feature_request(const char *feature_list, const char *feature)
{
- return !!parse_feature_value(feature_list, feature, NULL);
+ return !!parse_feature_value(feature_list, feature, NULL, NULL);
+}
+
+static const char *next_server_feature_value(const char *feature, size_t *len, size_t *offset)
+{
+ return parse_feature_value(server_capabilities_v1, feature, len, offset);
}
-const char *server_feature_value(const char *feature, int *len)
+const char *server_feature_value(const char *feature, size_t *len)
{
- return parse_feature_value(server_capabilities_v1, feature, len);
+ return parse_feature_value(server_capabilities_v1, feature, len, NULL);
}
int server_supports(const char *feature)
@@ -778,7 +965,7 @@ static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
static char *git_proxy_command;
static int git_proxy_command_options(const char *var, const char *value,
- void *cb)
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.gitproxy")) {
const char *for_pos;
@@ -824,7 +1011,7 @@ static int git_proxy_command_options(const char *var, const char *value,
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int git_use_proxy(const char *host)
@@ -848,9 +1035,9 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
proxy = xmalloc(sizeof(*proxy));
child_process_init(proxy);
- argv_array_push(&proxy->args, git_proxy_command);
- argv_array_push(&proxy->args, host);
- argv_array_push(&proxy->args, port);
+ strvec_push(&proxy->args, git_proxy_command);
+ strvec_push(&proxy->args, host);
+ strvec_push(&proxy->args, port);
proxy->in = -1;
proxy->out = -1;
if (start_command(proxy))
@@ -956,7 +1143,7 @@ static const char *get_ssh_command(void)
if ((ssh = getenv("GIT_SSH_COMMAND")))
return ssh;
- if (!git_config_get_string_const("core.sshcommand", &ssh))
+ if (!git_config_get_string_tmp("core.sshcommand", &ssh))
return ssh;
return NULL;
@@ -975,7 +1162,7 @@ static void override_ssh_variant(enum ssh_variant *ssh_variant)
{
const char *variant = getenv("GIT_SSH_VARIANT");
- if (!variant && git_config_get_string_const("ssh.variant", &variant))
+ if (!variant && git_config_get_string_tmp("ssh.variant", &variant))
return;
if (!strcmp(variant, "auto"))
@@ -1064,6 +1251,8 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
target_host = xstrdup(hostandport);
transport_check_allowed("git");
+ if (strchr(target_host, '\n') || strchr(path, '\n'))
+ die(_("newline is forbidden in git:// hosts and repo paths"));
/*
* These underlying connection commands die() if they
@@ -1103,16 +1292,16 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
* Append the appropriate environment variables to `env` and options to
* `args` for running ssh in Git's SSH-tunneled transport.
*/
-static void push_ssh_options(struct argv_array *args, struct argv_array *env,
+static void push_ssh_options(struct strvec *args, struct strvec *env,
enum ssh_variant variant, const char *port,
enum protocol_version version, int flags)
{
if (variant == VARIANT_SSH &&
version > 0) {
- argv_array_push(args, "-o");
- argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
- argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
- version);
+ strvec_push(args, "-o");
+ strvec_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
+ strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
+ version);
}
if (flags & CONNECT_IPV4) {
@@ -1125,7 +1314,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
- argv_array_push(args, "-4");
+ strvec_push(args, "-4");
}
} else if (flags & CONNECT_IPV6) {
switch (variant) {
@@ -1137,12 +1326,12 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
- argv_array_push(args, "-6");
+ strvec_push(args, "-6");
}
}
if (variant == VARIANT_TORTOISEPLINK)
- argv_array_push(args, "-batch");
+ strvec_push(args, "-batch");
if (port) {
switch (variant) {
@@ -1151,15 +1340,15 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_SIMPLE:
die(_("ssh variant 'simple' does not support setting port"));
case VARIANT_SSH:
- argv_array_push(args, "-p");
+ strvec_push(args, "-p");
break;
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
- argv_array_push(args, "-P");
+ strvec_push(args, "-P");
}
- argv_array_push(args, port);
+ strvec_push(args, port);
}
}
@@ -1197,18 +1386,19 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
detect.use_shell = conn->use_shell;
detect.no_stdin = detect.no_stdout = detect.no_stderr = 1;
- argv_array_push(&detect.args, ssh);
- argv_array_push(&detect.args, "-G");
- push_ssh_options(&detect.args, &detect.env_array,
+ strvec_push(&detect.args, ssh);
+ strvec_push(&detect.args, "-G");
+ push_ssh_options(&detect.args, &detect.env,
VARIANT_SSH, port, version, flags);
- argv_array_push(&detect.args, ssh_host);
+ strvec_push(&detect.args, ssh_host);
variant = run_command(&detect) ? VARIANT_SIMPLE : VARIANT_SSH;
}
- argv_array_push(&conn->args, ssh);
- push_ssh_options(&conn->args, &conn->env_array, variant, port, version, flags);
- argv_array_push(&conn->args, ssh_host);
+ strvec_push(&conn->args, ssh);
+ push_ssh_options(&conn->args, &conn->env, variant, port, version,
+ flags);
+ strvec_push(&conn->args, ssh_host);
}
/*
@@ -1223,6 +1413,7 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
* the connection failed).
*/
struct child_process *git_connect(int fd[2], const char *url,
+ const char *name,
const char *prog, int flags)
{
char *hostandport, *path;
@@ -1232,10 +1423,11 @@ struct child_process *git_connect(int fd[2], const char *url,
/*
* NEEDSWORK: If we are trying to use protocol v2 and we are planning
- * to perform a push, then fallback to v0 since the client doesn't know
- * how to push yet using v2.
+ * to perform any operation that doesn't involve upload-pack (i.e., a
+ * fetch, ls-remote, etc), then fallback to v0 since we don't know how
+ * to do anything else (like push or remote archive) via v2.
*/
- if (version == protocol_v2 && !strcmp("git-receive-pack", prog))
+ if (version == protocol_v2 && strcmp("git-upload-pack", name))
version = protocol_v0;
/* Without this we cannot rely on waitpid() to tell
@@ -1269,7 +1461,7 @@ struct child_process *git_connect(int fd[2], const char *url,
/* remove repo-local variables from the environment */
for (var = local_repo_env; *var; var++)
- argv_array_push(&conn->env_array, *var);
+ strvec_push(&conn->env, *var);
conn->use_shell = 1;
conn->in = conn->out = -1;
@@ -1301,11 +1493,12 @@ struct child_process *git_connect(int fd[2], const char *url,
transport_check_allowed("file");
conn->trace2_child_class = "transport/file";
if (version > 0) {
- argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
- version);
+ strvec_pushf(&conn->env,
+ GIT_PROTOCOL_ENVIRONMENT "=version=%d",
+ version);
}
}
- argv_array_push(&conn->args, cmd.buf);
+ strvec_push(&conn->args, cmd.buf);
if (start_command(conn))
die(_("unable to fork"));