summaryrefslogtreecommitdiff
path: root/src/transports
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-11-10 07:31:21 -0800
committerVicent Martí <vicent@github.com>2013-11-10 07:31:21 -0800
commit0df96f2b05f45e62047fc592ded37c0ef18ec27b (patch)
treeabbfd0757d065fda064f5a2276df783b7b535319 /src/transports
parent4cb3c7abe1a56ef93d2e0078ad86d09aed0cccce (diff)
parent79c443425b1b3d67e8180663c6e80793b587c888 (diff)
downloadlibgit2-0df96f2b05f45e62047fc592ded37c0ef18ec27b.tar.gz
Merge pull request #1936 from libgit2/better-url-parsing
Streamline url-parsing logic.
Diffstat (limited to 'src/transports')
-rw-r--r--src/transports/git.c72
-rw-r--r--src/transports/ssh.c6
2 files changed, 33 insertions, 45 deletions
diff --git a/src/transports/git.c b/src/transports/git.c
index 79a9e7dd4..5dcd4eff7 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -179,39 +179,33 @@ static int _git_uploadpack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- char *host=NULL, *port=NULL, *user=NULL, *pass=NULL;
+ char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
+ const char *stream_url = url;
git_stream *s;
+ int error = -1;
*stream = NULL;
-
if (!git__prefixcmp(url, prefix_git))
- url += strlen(prefix_git);
+ stream_url += strlen(prefix_git);
- if (git_stream_alloc(t, url, cmd_uploadpack, stream) < 0)
+ if (git_stream_alloc(t, stream_url, cmd_uploadpack, stream) < 0)
return -1;
s = (git_stream *)*stream;
- if (gitno_extract_url_parts(&host, &port, &user, &pass, url, GIT_DEFAULT_PORT) < 0)
- goto on_error;
-
- if (gitno_connect(&s->socket, host, port, 0) < 0)
- goto on_error;
-
- t->current_stream = s;
- git__free(host);
- git__free(port);
- git__free(user);
- git__free(pass);
- return 0;
+ if (!(error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, GIT_DEFAULT_PORT))) {
+ if (!(error = gitno_connect(&s->socket, host, port, 0)))
+ t->current_stream = s;
-on_error:
- if (*stream)
+ git__free(host);
+ git__free(port);
+ git__free(path);
+ git__free(user);
+ git__free(pass);
+ } else if (*stream)
git_stream_free(*stream);
- git__free(host);
- git__free(port);
- return -1;
+ return error;
}
static int _git_uploadpack(
@@ -235,39 +229,33 @@ static int _git_receivepack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- char *host=NULL, *port=NULL, *user=NULL, *pass=NULL;
+ char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
+ const char *stream_url = url;
git_stream *s;
+ int error;
*stream = NULL;
-
if (!git__prefixcmp(url, prefix_git))
- url += strlen(prefix_git);
+ stream_url += strlen(prefix_git);
- if (git_stream_alloc(t, url, cmd_receivepack, stream) < 0)
+ if (git_stream_alloc(t, stream_url, cmd_receivepack, stream) < 0)
return -1;
s = (git_stream *)*stream;
- if (gitno_extract_url_parts(&host, &port, &user, &pass, url, GIT_DEFAULT_PORT) < 0)
- goto on_error;
-
- if (gitno_connect(&s->socket, host, port, 0) < 0)
- goto on_error;
-
- t->current_stream = s;
- git__free(host);
- git__free(port);
- git__free(user);
- git__free(pass);
- return 0;
+ if (!(error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, GIT_DEFAULT_PORT))) {
+ if (!(error = gitno_connect(&s->socket, host, port, 0)))
+ t->current_stream = s;
-on_error:
- if (*stream)
+ git__free(host);
+ git__free(port);
+ git__free(path);
+ git__free(user);
+ git__free(pass);
+ } else if (*stream)
git_stream_free(*stream);
- git__free(host);
- git__free(port);
- return -1;
+ return error;
}
static int _git_receivepack(
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 4e2834b49..4a905e3c9 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -317,7 +317,7 @@ static int _git_ssh_setup_conn(
const char *cmd,
git_smart_subtransport_stream **stream)
{
- char *host=NULL, *port=NULL, *user=NULL, *pass=NULL;
+ char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
const char *default_port="22";
ssh_stream *s;
LIBSSH2_SESSION* session=NULL;
@@ -330,8 +330,7 @@ static int _git_ssh_setup_conn(
s = (ssh_stream *)*stream;
if (!git__prefixcmp(url, prefix_ssh)) {
- url = url + strlen(prefix_ssh);
- if (gitno_extract_url_parts(&host, &port, &user, &pass, url, default_port) < 0)
+ if (gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port) < 0)
goto on_error;
} else {
if (git_ssh_extract_url_parts(&host, &user, url) < 0)
@@ -390,6 +389,7 @@ static int _git_ssh_setup_conn(
t->current_stream = s;
git__free(host);
git__free(port);
+ git__free(path);
git__free(user);
git__free(pass);