Commit ff8e3f0e by Chris Bargren Committed by Edward Thomson

Handle git+ssh:// and ssh+git:// protocols support

parent 2f2575c0
...@@ -35,6 +35,8 @@ static transport_definition transports[] = { ...@@ -35,6 +35,8 @@ static transport_definition transports[] = {
{ "file://", git_transport_local, NULL }, { "file://", git_transport_local, NULL },
#ifdef GIT_SSH #ifdef GIT_SSH
{ "ssh://", git_transport_smart, &ssh_subtransport_definition }, { "ssh://", git_transport_smart, &ssh_subtransport_definition },
{ "ssh+git://", git_transport_smart, &ssh_subtransport_definition },
{ "git+ssh://", git_transport_smart, &ssh_subtransport_definition },
#endif #endif
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport) #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://" };
#define SSH_PREFIX_COUNT (sizeof(ssh_prefixes) / sizeof(ssh_prefixes[0]))
static const char cmd_uploadpack[] = "git-upload-pack"; static const char cmd_uploadpack[] = "git-upload-pack";
static const char cmd_receivepack[] = "git-receive-pack"; static const char cmd_receivepack[] = "git-receive-pack";
...@@ -64,16 +66,23 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) ...@@ -64,16 +66,23 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
char *repo; char *repo;
int len; int len;
if (!git__prefixcmp(url, prefix_ssh)) { size_t i = 0;
url = url + strlen(prefix_ssh); for (i = 0; i < SSH_PREFIX_COUNT; ++i) {
repo = strchr(url, '/'); const char *p = ssh_prefixes[i];
if (repo && repo[1] == '~')
++repo; if (!git__prefixcmp(url, p)) {
} else { url = url + strlen(p);
repo = strchr(url, ':'); repo = strchr(url, '/');
if (repo) repo++; if (repo && repo[1] == '~')
++repo;
goto done;
}
} }
repo = strchr(url, ':');
if (repo) repo++;
done:
if (!repo) { if (!repo) {
giterr_set(GITERR_NET, "Malformed git protocol URL"); giterr_set(GITERR_NET, "Malformed git protocol URL");
return -1; return -1;
...@@ -515,16 +524,23 @@ static int _git_ssh_setup_conn( ...@@ -515,16 +524,23 @@ static int _git_ssh_setup_conn(
s->session = NULL; s->session = NULL;
s->channel = NULL; s->channel = NULL;
if (!git__prefixcmp(url, prefix_ssh)) { size_t i = 0;
if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0) for (i = 0; i < SSH_PREFIX_COUNT; ++i) {
goto done; const char *p = ssh_prefixes[i];
} else {
if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0) if (!git__prefixcmp(url, p)) {
goto done; if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0)
port = git__strdup(default_port); goto done;
GITERR_CHECK_ALLOC(port);
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 || if ((error = git_socket_stream_new(&s->io, host, port)) < 0 ||
(error = git_stream_connect(s->io)) < 0) (error = git_stream_connect(s->io)) < 0)
goto done; goto done;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment