X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=connect.c;h=e21d39a3574ff0815520187d21624970b19da92f;hb=f6804930cae3ccf48b200264bdb7a25b4382d454;hp=20b80a1b54b965d4af272aa7cb7c0009c737e4dd;hpb=d59a6043a8a7aed97c684fb4f14fe5221df1fcaf;p=git.git diff --git a/connect.c b/connect.c index 20b80a1b..e21d39a3 100644 --- a/connect.c +++ b/connect.c @@ -1,6 +1,7 @@ #include "cache.h" #include "pkt-line.h" #include "quote.h" +#include "refs.h" #include #include #include @@ -10,7 +11,8 @@ /* * Read all the refs from the other end */ -struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match) +struct ref **get_remote_heads(int in, struct ref **list, + int nr_match, char **match, int ignore_funny) { *list = NULL; for (;;) { @@ -29,6 +31,11 @@ struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **ma if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ') die("protocol error: expected sha/ref, got '%s'", buffer); name = buffer + 41; + + if (ignore_funny && 45 < len && !memcmp(name, "refs/", 5) && + check_ref_format(name + 5)) + continue; + if (nr_match && !path_match(name, nr_match, match)) continue; ref = xcalloc(1, sizeof(*ref) + len - 40); @@ -82,15 +89,26 @@ int path_match(const char *path, int nr, char **match) struct refspec { char *src; char *dst; + char force; }; +/* + * A:B means fast forward remote B with local A. + * +A:B means overwrite remote B with local A. + * +A is a shorthand for +A:A. + * A is a shorthand for A:A. + */ static struct refspec *parse_ref_spec(int nr_refspec, char **refspec) { int i; - struct refspec *rs = xmalloc(sizeof(*rs) * (nr_refspec + 1)); + struct refspec *rs = xcalloc(sizeof(*rs), (nr_refspec + 1)); for (i = 0; i < nr_refspec; i++) { char *sp, *dp, *ep; sp = refspec[i]; + if (*sp == '+') { + rs[i].force = 1; + sp++; + } ep = strchr(sp, ':'); if (ep) { dp = ep + 1; @@ -166,7 +184,8 @@ static int match_explicit_refs(struct ref *src, struct ref *dst, if (matched_src) break; errs = 1; - error("src refspec %s does not match any."); + error("src refspec %s does not match any.", + rs[i].src); break; default: errs = 1; @@ -215,8 +234,10 @@ static int match_explicit_refs(struct ref *src, struct ref *dst, error("dst ref %s receives from more than one src.", matched_dst->name); } - else + else { matched_dst->peer_ref = matched_src; + matched_dst->force = rs[i].force; + } } return -errs; } @@ -381,8 +402,17 @@ int git_connect(int fd[2], char *url, const char *prog) close(pipefd[0][1]); close(pipefd[1][0]); close(pipefd[1][1]); - if (protocol == PROTO_SSH) - execlp("ssh", "ssh", host, command, NULL); + if (protocol == PROTO_SSH) { + const char *ssh, *ssh_basename; + ssh = getenv("GIT_SSH"); + if (!ssh) ssh = "ssh"; + ssh_basename = strrchr(ssh, '/'); + if (!ssh_basename) + ssh_basename = ssh; + else + ssh_basename++; + execlp(ssh, ssh_basename, host, command, NULL); + } else execlp("sh", "sh", "-c", command, NULL); die("exec failed");