Cleanup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 935fe58..cc27c8d 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -26,6 +26,7 @@ typedef struct {
LIBSSH2_CHANNEL *channel;
const char *cmd;
char *url;
+ char *path;
unsigned sent_command : 1;
} ssh_stream;
@@ -39,21 +40,11 @@ typedef struct {
/*
* 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;
- 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;
+ int len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
git_buf_grow(request, len);
git_buf_printf(request, "%s '%s'", cmd, repo);
@@ -70,7 +61,7 @@ static int send_command(ssh_stream *s)
int error;
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)
goto cleanup;
@@ -276,7 +267,7 @@ static int _git_receivepack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- char *host, *path, *user=NULL;
+ char *host, *user=NULL;
ssh_stream *s;
*stream = NULL;
@@ -285,7 +276,7 @@ static int _git_receivepack_ls(
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;
if (gitno_connect(&s->socket, host, "22", 0) < 0)
@@ -356,7 +347,6 @@ on_error:
ssh_stream_free(*stream);
git__free(host);
- git__free(path);
return -1;
}