Skip to content

Commit c2bdef6

Browse files
Edward Thomsonethomson
authored andcommitted
net: parse urls or scp style paths in the same function
1 parent cfc3b37 commit c2bdef6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/libgit2/transports/ssh.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,8 @@ static int _git_ssh_setup_conn(
788788
s->session = NULL;
789789
s->channel = NULL;
790790

791-
if (git_net_str_is_url(url))
792-
error = git_net_url_parse(&s->url, url);
793-
else
794-
error = git_net_url_parse_scp(&s->url, url);
795-
796-
if (error < 0)
797-
goto done;
798-
799-
if ((error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
791+
if ((error = git_net_url_parse_standard_or_scp(&s->url, url)) < 0 ||
792+
(error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
800793
(error = git_stream_connect(s->io)) < 0)
801794
goto done;
802795

@@ -806,8 +799,11 @@ static int _git_ssh_setup_conn(
806799
* as part of the stream connection, but that's not something that's
807800
* exposed.
808801
*/
809-
if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0)
810-
port = -1;
802+
if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) {
803+
git_error_set(GIT_ERROR_NET, "invalid port to ssh: %s", s->url.port);
804+
error = -1;
805+
goto done;
806+
}
811807

812808
if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0)
813809
goto done;

src/util/net.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,13 @@ int git_net_url_parse_scp(git_net_url *url, const char *given)
646646
return 0;
647647
}
648648

649+
int git_net_url_parse_standard_or_scp(git_net_url *url, const char *given)
650+
{
651+
return git_net_str_is_url(given) ?
652+
git_net_url_parse(url, given) :
653+
git_net_url_parse_scp(url, given);
654+
}
655+
649656
int git_net_url_joinpath(
650657
git_net_url *out,
651658
git_net_url *one,

src/util/net.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ extern int git_net_url_parse(git_net_url *url, const char *str);
3434
/** Parses a string containing an SCP style path into a URL structure. */
3535
extern int git_net_url_parse_scp(git_net_url *url, const char *str);
3636

37+
/**
38+
* Parses a string containing a standard URL or an SCP style path into
39+
* a URL structure.
40+
*/
41+
extern int git_net_url_parse_standard_or_scp(git_net_url *url, const char *str);
42+
3743
/** Appends a path and/or query string to the given URL */
3844
extern int git_net_url_joinpath(
3945
git_net_url *out,

0 commit comments

Comments
 (0)