Refactoring
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index a186c22..6e99e00 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -215,72 +215,18 @@ static int gitssh_extract_url_parts(
return 0;
}
-static int _git_uploadpack_ls(
+static int _git_ssh_setup_conn(
ssh_subtransport *t,
const char *url,
- git_smart_subtransport_stream **stream)
-{
- char *host, *port, *user=NULL, *pass=NULL;
- ssh_stream *s;
-
- *stream = NULL;
-
- if (!git__prefixcmp(url, prefix_ssh))
- url += strlen(prefix_ssh);
-
- if (ssh_stream_alloc(t, url, cmd_uploadpack, stream) < 0)
- return -1;
-
- s = (ssh_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;
-
-on_error:
- if (*stream)
- ssh_stream_free(*stream);
-
- git__free(host);
- git__free(port);
- return -1;
-}
-
-static int _git_uploadpack(
- ssh_subtransport *t,
- const char *url,
- git_smart_subtransport_stream **stream)
-{
- GIT_UNUSED(url);
-
- if (t->current_stream) {
- *stream = &t->current_stream->parent;
- return 0;
- }
-
- giterr_set(GITERR_NET, "Must call UPLOADPACK_LS before UPLOADPACK");
- return -1;
-}
-
-static int _git_receivepack_ls(
- ssh_subtransport *t,
- const char *url,
- git_smart_subtransport_stream **stream)
+ const char *cmd,
+ git_smart_subtransport_stream **stream
+)
{
char *host, *user=NULL;
ssh_stream *s;
*stream = NULL;
- if (ssh_stream_alloc(t, url, cmd_receivepack, stream) < 0)
+ if (ssh_stream_alloc(t, url, cmd, stream) < 0)
return -1;
s = (ssh_stream *)*stream;
@@ -359,6 +305,44 @@ on_error:
return -1;
}
+static int _git_uploadpack_ls(
+ ssh_subtransport *t,
+ const char *url,
+ git_smart_subtransport_stream **stream)
+{
+ if (_git_ssh_setup_conn(t, url, cmd_uploadpack, stream) < 0)
+ return -1;
+
+ return 0;
+}
+
+static int _git_uploadpack(
+ ssh_subtransport *t,
+ const char *url,
+ git_smart_subtransport_stream **stream)
+{
+ GIT_UNUSED(url);
+
+ if (t->current_stream) {
+ *stream = &t->current_stream->parent;
+ return 0;
+ }
+
+ giterr_set(GITERR_NET, "Must call UPLOADPACK_LS before UPLOADPACK");
+ return -1;
+}
+
+static int _git_receivepack_ls(
+ ssh_subtransport *t,
+ const char *url,
+ git_smart_subtransport_stream **stream)
+{
+ if (_git_ssh_setup_conn(t, url, cmd_receivepack, stream) < 0)
+ return -1;
+
+ return 0;
+}
+
static int _git_receivepack(
ssh_subtransport *t,
const char *url,