{"thread":{"id":"9737","subject":"[PATCH] URL: allow port specification in ssh:// URLs","startedAt":"2007-09-01T09:36:31Z","lastAt":"2007-09-01T11:13:01Z","messageCount":3,"participants":["Luben Tuikov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52135","messageId":"583261.77513.qm@web31802.mail.mud.yahoo.com","threadId":"9737","inReplyTo":null,"subject":"[PATCH] URL: allow port specification in ssh:// URLs","fromName":"Luben Tuikov","fromEmail":"ltuikov@yahoo.com","sentAt":"2007-09-01T09:36:31Z","receivedAt":"2007-09-01T09:36:31Z","isPatch":true,"sender":{"key":"ltuikov@yahoo.com","avatar":null},"body":"Allow port specification in ssh:// URLs in the\nusual notation:\n\tssh://[user@]host.domain[:<port>]/<path>\n\nThis allows git to be used over ssh-tunneling\nnetworks.\n\nSigned-off-by: Luben Tuikov <ltuikov@yahoo.com>\n---\n Documentation/urls.txt |    4 +++-\n connect.c              |   30 +++++++++++++++++++++++++++++-\n 2 files changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/urls.txt b/Documentation/urls.txt\nindex b38145f..e67f914 100644\n--- a/Documentation/urls.txt\n+++ b/Documentation/urls.txt\n@@ -10,6 +10,7 @@ to name the remote repository:\n - https://host.xz/path/to/repo.git/\n - git://host.xz/path/to/repo.git/\n - git://host.xz/~user/path/to/repo.git/\n+- ssh://{startsb}user@{endsb}host.xz{startsb}:port{endsb}/path/to/repo.git/\n - ssh://{startsb}user@{endsb}host.xz/path/to/repo.git/\n - ssh://{startsb}user@{endsb}host.xz/~user/path/to/repo.git/\n - ssh://{startsb}user@{endsb}host.xz/~/path/to/repo.git\n@@ -18,7 +19,8 @@ to name the remote repository:\n SSH is the default transport protocol over the network.  You can\n optionally specify which user to log-in as, and an alternate,\n scp-like syntax is also supported.  Both syntaxes support\n-username expansion, as does the native git protocol. The following\n+username expansion, as does the native git protocol, but\n+only the former supports port specification. The following\n three are identical to the last three above, respectively:\n \n ===============================================================\ndiff --git a/connect.c b/connect.c\nindex ae49c5a..8b1e993 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -453,6 +453,22 @@ static void git_proxy_connect(int fd[2], char *host)\n \n #define MAX_CMD_LEN 1024\n \n+char *get_port(char *host)\n+{\n+\tchar *end;\n+\tchar *p = strchr(host, ':');\n+\n+\tif (p) {\n+\t\tstrtol(p+1, &end, 10);\n+\t\tif (*end == '\\0') {\n+\t\t\t*p = '\\0';\n+\t\t\treturn p+1;\n+\t\t}\n+\t}\n+\n+\treturn NULL;\n+}\n+\n /*\n  * This returns 0 if the transport protocol does not need fork(2),\n  * or a process id if it does.  Once done, finish the connection\n@@ -471,6 +487,7 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)\n \tpid_t pid;\n \tenum protocol protocol = PROTO_LOCAL;\n \tint free_path = 0;\n+\tchar *port = NULL;\n \n \t/* Without this we cannot rely on waitpid() to tell\n \t * what happened to our children.\n@@ -527,6 +544,12 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)\n \t\t*ptr = '\\0';\n \t}\n \n+\t/*\n+\t * Add support for ssh port: ssh://host.xy:<port>/...\n+\t */\n+\tif (protocol == PROTO_SSH && host != url)\n+\t\tport = get_port(host);\n+\n \tif (protocol == PROTO_GIT) {\n \t\t/* These underlying connection commands die() if they\n \t\t * cannot connect.\n@@ -583,7 +606,12 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)\n \t\t\t\tssh_basename = ssh;\n \t\t\telse\n \t\t\t\tssh_basename++;\n-\t\t\texeclp(ssh, ssh_basename, host, command, NULL);\n+\n+\t\t\tif (!port)\n+\t\t\t\texeclp(ssh, ssh_basename, host, command, NULL);\n+\t\t\telse\n+\t\t\t\texeclp(ssh, ssh_basename, \"-p\", port, host,\n+\t\t\t\t       command, NULL);\n \t\t}\n \t\telse {\n \t\t\tunsetenv(ALTERNATE_DB_ENVIRONMENT);\n-- \n1.5.3.rc7.1278.g0f6d\n"},{"id":"52137","messageId":"7v1wdiu1x2.fsf@gitster.siamese.dyndns.org","threadId":"9737","inReplyTo":"583261.77513.qm@web31802.mail.mud.yahoo.com","subject":"Re: [PATCH] URL: allow port specification in ssh:// URLs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-01T10:15:37Z","receivedAt":"2007-09-01T10:15:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicely done.\n\nAlthough none of this may be strictly necessary (you can always\nadd entries to ~/.ssh/config), people often got confused because\nwe did not support this syntax.\n\nThanks.\n"},{"id":"52141","messageId":"377758.23919.qm@web31802.mail.mud.yahoo.com","threadId":"9737","inReplyTo":"7v1wdiu1x2.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] URL: allow port specification in ssh:// URLs","fromName":"Luben Tuikov","fromEmail":"ltuikov@yahoo.com","sentAt":"2007-09-01T11:13:01Z","receivedAt":"2007-09-01T11:13:01Z","isPatch":true,"sender":{"key":"ltuikov@yahoo.com","avatar":null},"body":"--- Junio C Hamano <gitster@pobox.com> wrote:\n> Nicely done.\n\nThanks!\n\n    Luben\n"}]}