Commit 58ba0a4e by Brad Morgan

Cleanup

parent f7158cd7
...@@ -26,6 +26,7 @@ typedef struct { ...@@ -26,6 +26,7 @@ typedef struct {
LIBSSH2_CHANNEL *channel; LIBSSH2_CHANNEL *channel;
const char *cmd; const char *cmd;
char *url; char *url;
char *path;
unsigned sent_command : 1; unsigned sent_command : 1;
} ssh_stream; } ssh_stream;
...@@ -39,21 +40,11 @@ typedef struct { ...@@ -39,21 +40,11 @@ typedef struct {
/* /*
* Create a git protocol request. * Create a git protocol request.
* *
* For example: 0035git-upload-pack /libgit2/libgit2\0 * For example: git-upload-pack '/libgit2/libgit2'
*/ */
static int gen_proto(git_buf *request, const char *cmd, const char *url) static int gen_proto(git_buf *request, const char *cmd, const char *repo)
{ {
char *delim, *repo; int len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
size_t len;
delim = strchr(url, ':');
if (delim == NULL) {
giterr_set(GITERR_NET, "Malformed URL");
return -1;
}
repo = delim+1;
len = strlen(cmd) + 1 + 1 + strlen(repo) + 1;
git_buf_grow(request, len); git_buf_grow(request, len);
git_buf_printf(request, "%s '%s'", cmd, repo); git_buf_printf(request, "%s '%s'", cmd, repo);
...@@ -70,7 +61,7 @@ static int send_command(ssh_stream *s) ...@@ -70,7 +61,7 @@ static int send_command(ssh_stream *s)
int error; int error;
git_buf request = GIT_BUF_INIT; git_buf request = GIT_BUF_INIT;
error = gen_proto(&request, s->cmd, s->url); error = gen_proto(&request, s->cmd, s->path);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
...@@ -276,7 +267,7 @@ static int _git_receivepack_ls( ...@@ -276,7 +267,7 @@ static int _git_receivepack_ls(
const char *url, const char *url,
git_smart_subtransport_stream **stream) git_smart_subtransport_stream **stream)
{ {
char *host, *path, *user=NULL; char *host, *user=NULL;
ssh_stream *s; ssh_stream *s;
*stream = NULL; *stream = NULL;
...@@ -285,7 +276,7 @@ static int _git_receivepack_ls( ...@@ -285,7 +276,7 @@ static int _git_receivepack_ls(
s = (ssh_stream *)*stream; s = (ssh_stream *)*stream;
if (gitssh_extract_url_parts(&host, &user, &path, url) < 0) if (gitssh_extract_url_parts(&host, &user, &s->path, url) < 0)
goto on_error; goto on_error;
if (gitno_connect(&s->socket, host, "22", 0) < 0) if (gitno_connect(&s->socket, host, "22", 0) < 0)
...@@ -356,7 +347,6 @@ on_error: ...@@ -356,7 +347,6 @@ on_error:
ssh_stream_free(*stream); ssh_stream_free(*stream);
git__free(host); git__free(host);
git__free(path);
return -1; return -1;
} }
......
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