URL: allow port specification in ssh:// URLs
Allow port specification in ssh:// URLs in the usual notation: ssh://[user@]host.domain[:<port>]/<path> This allows git to be used over ssh-tunneling networks. Signed-off-by: Luben Tuikov <ltuikov@yahoo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luben Tuikov committed
Sep 1, 2007 at 02:36 UTC
2e7766655abd0312a6bf4db6a6ff141e7e4ac8b6
2 files changed
+32
-2
Documentation/urls.txt
+3
-1
@@ -10,6 +10,7 @@ to name the remote repository:
10
- https://host.xz/path/to/repo.git/
11
- git://host.xz/path/to/repo.git/
12
- git://host.xz/~user/path/to/repo.git/
13
+- ssh://{startsb}user@{endsb}host.xz{startsb}:port{endsb}/path/to/repo.git/
14
- ssh://{startsb}user@{endsb}host.xz/path/to/repo.git/
15
- ssh://{startsb}user@{endsb}host.xz/~user/path/to/repo.git/
16
- ssh://{startsb}user@{endsb}host.xz/~/path/to/repo.git
@@ -18,7 +19,8 @@ to name the remote repository:
19
SSH is the default transport protocol over the network. You can
20
optionally specify which user to log-in as, and an alternate,
21
scp-like syntax is also supported. Both syntaxes support
21
-username expansion, as does the native git protocol. The following
22
+username expansion, as does the native git protocol, but
23
+only the former supports port specification. The following
24
three are identical to the last three above, respectively:
25
26
===============================================================
connect.c
+29
-1
@@ -453,6 +453,22 @@ static void git_proxy_connect(int fd[2], char *host)
453
454
#define MAX_CMD_LEN 1024
455
456
+char *get_port(char *host)
457
+{
458
+ char *end;
459
+ char *p = strchr(host, ':');
460
+
461
+ if (p) {
462
+ strtol(p+1, &end, 10);
463
+ if (*end == '\0') {
464
+ *p = '\0';
465
+ return p+1;
466
+ }
467
+ }
468
+
469
+ return NULL;
470
+}
471
+
472
/*
473
* This returns 0 if the transport protocol does not need fork(2),
474
* or a process id if it does. Once done, finish the connection
@@ -471,6 +487,7 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
487
pid_t pid;
488
enum protocol protocol = PROTO_LOCAL;
489
int free_path = 0;
490
+ char *port = NULL;
491
492
/* Without this we cannot rely on waitpid() to tell
493
* what happened to our children.
@@ -527,6 +544,12 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
544
*ptr = '\0';
545
}
546
547
+ /*
548
+ * Add support for ssh port: ssh://host.xy:<port>/...
549
+ */
550
+ if (protocol == PROTO_SSH && host != url)
551
+ port = get_port(host);
552
+
553
if (protocol == PROTO_GIT) {
554
/* These underlying connection commands die() if they
555
* cannot connect.
@@ -583,7 +606,12 @@ pid_t git_connect(int fd[2], char *url, const char *prog, int flags)
606
ssh_basename = ssh;
607
else
608
ssh_basename++;
586
- execlp(ssh, ssh_basename, host, command, NULL);
609
+
610
+ if (!port)
611
+ execlp(ssh, ssh_basename, host, command, NULL);
612
+ else
613
+ execlp(ssh, ssh_basename, "-p", port, host,
614
+ command, NULL);
615
}
616
else {
617
unsetenv(ALTERNATE_DB_ENVIRONMENT);