Commit c2bdef6f by Edward Thomson Committed by Edward Thomson

net: parse urls or scp style paths in the same function

parent cfc3b379
...@@ -788,15 +788,8 @@ static int _git_ssh_setup_conn( ...@@ -788,15 +788,8 @@ static int _git_ssh_setup_conn(
s->session = NULL; s->session = NULL;
s->channel = NULL; s->channel = NULL;
if (git_net_str_is_url(url)) if ((error = git_net_url_parse_standard_or_scp(&s->url, url)) < 0 ||
error = git_net_url_parse(&s->url, url); (error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
else
error = git_net_url_parse_scp(&s->url, url);
if (error < 0)
goto done;
if ((error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
(error = git_stream_connect(s->io)) < 0) (error = git_stream_connect(s->io)) < 0)
goto done; goto done;
...@@ -806,8 +799,11 @@ static int _git_ssh_setup_conn( ...@@ -806,8 +799,11 @@ static int _git_ssh_setup_conn(
* as part of the stream connection, but that's not something that's * as part of the stream connection, but that's not something that's
* exposed. * exposed.
*/ */
if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) {
port = -1; git_error_set(GIT_ERROR_NET, "invalid port to ssh: %s", s->url.port);
error = -1;
goto done;
}
if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0) if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0)
goto done; goto done;
......
...@@ -646,6 +646,13 @@ int git_net_url_parse_scp(git_net_url *url, const char *given) ...@@ -646,6 +646,13 @@ int git_net_url_parse_scp(git_net_url *url, const char *given)
return 0; return 0;
} }
int git_net_url_parse_standard_or_scp(git_net_url *url, const char *given)
{
return git_net_str_is_url(given) ?
git_net_url_parse(url, given) :
git_net_url_parse_scp(url, given);
}
int git_net_url_joinpath( int git_net_url_joinpath(
git_net_url *out, git_net_url *out,
git_net_url *one, git_net_url *one,
......
...@@ -34,6 +34,12 @@ extern int git_net_url_parse(git_net_url *url, const char *str); ...@@ -34,6 +34,12 @@ extern int git_net_url_parse(git_net_url *url, const char *str);
/** Parses a string containing an SCP style path into a URL structure. */ /** Parses a string containing an SCP style path into a URL structure. */
extern int git_net_url_parse_scp(git_net_url *url, const char *str); extern int git_net_url_parse_scp(git_net_url *url, const char *str);
/**
* Parses a string containing a standard URL or an SCP style path into
* a URL structure.
*/
extern int git_net_url_parse_standard_or_scp(git_net_url *url, const char *str);
/** Appends a path and/or query string to the given URL */ /** Appends a path and/or query string to the given URL */
extern int git_net_url_joinpath( extern int git_net_url_joinpath(
git_net_url *out, git_net_url *out,
......
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