diff options
author | Edward Thomson <ethomson@github.com> | 2016-03-08 13:38:55 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-03-08 13:38:55 +0000 |
commit | b7809b84692b4df7f11d603cc5da0860609e0555 (patch) | |
tree | 786f1c6de61b29477d05f688764577db045b1de4 /src/transports | |
parent | 534ca8882d0247c749c23911b98423f2845cd1dc (diff) | |
parent | 813d73f64d779257fd24cd70bbc281352c34812b (diff) | |
download | libgit2-b7809b84692b4df7f11d603cc5da0860609e0555.tar.gz |
Merge pull request #3555 from cbargren/ssh-git-protocols
Support for ssh+git and git+ssh protocols
Diffstat (limited to 'src/transports')
-rw-r--r-- | src/transports/ssh.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/src/transports/ssh.c b/src/transports/ssh.c index 35739abe3..cfd573665 100644 --- a/src/transports/ssh.c +++ b/src/transports/ssh.c @@ -21,7 +21,8 @@ #define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport) -static const char prefix_ssh[] = "ssh://"; +static const char *ssh_prefixes[] = { "ssh://", "ssh+git://", "git+ssh://" }; + static const char cmd_uploadpack[] = "git-upload-pack"; static const char cmd_receivepack[] = "git-receive-pack"; @@ -63,17 +64,24 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) { char *repo; int len; + size_t i; - if (!git__prefixcmp(url, prefix_ssh)) { - url = url + strlen(prefix_ssh); - repo = strchr(url, '/'); - if (repo && repo[1] == '~') - ++repo; - } else { - repo = strchr(url, ':'); - if (repo) repo++; + for (i = 0; i < ARRAY_SIZE(ssh_prefixes); ++i) { + const char *p = ssh_prefixes[i]; + + if (!git__prefixcmp(url, p)) { + url = url + strlen(p); + repo = strchr(url, '/'); + if (repo && repo[1] == '~') + ++repo; + + goto done; + } } + repo = strchr(url, ':'); + if (repo) repo++; +done: if (!repo) { giterr_set(GITERR_NET, "Malformed git protocol URL"); return -1; @@ -500,6 +508,7 @@ static int _git_ssh_setup_conn( char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL; const char *default_port="22"; int auth_methods, error = 0; + size_t i; ssh_stream *s; git_cred *cred = NULL; LIBSSH2_SESSION* session=NULL; @@ -515,16 +524,22 @@ static int _git_ssh_setup_conn( s->session = NULL; s->channel = NULL; - if (!git__prefixcmp(url, prefix_ssh)) { - if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0) - goto done; - } else { - if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0) - goto done; - port = git__strdup(default_port); - GITERR_CHECK_ALLOC(port); + for (i = 0; i < ARRAY_SIZE(ssh_prefixes); ++i) { + const char *p = ssh_prefixes[i]; + + if (!git__prefixcmp(url, p)) { + if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0) + goto done; + + goto post_extract; + } } + if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0) + goto done; + port = git__strdup(default_port); + GITERR_CHECK_ALLOC(port); +post_extract: if ((error = git_socket_stream_new(&s->io, host, port)) < 0 || (error = git_stream_connect(s->io)) < 0) goto done; |