Commit Diff


commit - 58e1925afe722162950dec4569724ce73de3a294
commit + 62a4c94cd911a5c1ff54c4787c05d0876d30f07b
blob - 30f18d73f2400e6ec8f308802a304bc81ae8ea20
blob + 9d94bcc7fe798d02d848eb8412826ad908be6367
--- got/got.c
+++ got/got.c
@@ -1013,7 +1013,8 @@ cmd_clone(int argc, char *argv[])
 		goto done;
 
 	if (verbosity >= 0)
-		printf("Connected to %s:%s\n", host, port);
+		printf("Connected to %s%s%s\n", host,
+		    port ? ":" : "", port ? port : "");
 
 	/* Create a config file git-fetch(1) can understand. */
 	gitconfig_path = got_repo_get_path_gitconfig(repo);
@@ -1384,7 +1385,8 @@ cmd_fetch(int argc, char *argv[])
 		goto done;
 
 	if (verbosity >= 0)
-		printf("Connected to \"%s\" %s:%s\n", remote->name, host, port);
+		printf("Connected to \"%s\" %s%s%s\n", remote->name, host,
+		    port ? ":" : "", port ? port : "");
 
 	fpa.last_scaled_size[0] = '\0';
 	fpa.last_p_indexed = -1;
blob - 8edac2b231e81f398c49e2d59c055e3c84a443b1
blob + b5b03f3f8b3c2b8923bf764d7b8d82f18181c5eb
--- lib/fetch.c
+++ lib/fetch.c
@@ -89,24 +89,29 @@ dial_ssh(int *fetchfd, const char *host, const char *p
 	const struct got_error *error = NULL;
 	int pid, pfd[2];
 	char cmd[64];
-	char *argv[9];
+	char *argv[11];
 	int i = 0;
 
 	*fetchfd = -1;
 
+	if (port == NULL)
+		port = "22";
+
 	argv[0] = GOT_FETCH_PATH_SSH;
+	argv[1] = "-p";
+	argv[2] = (char *)port;
 	if (verbosity == -1) {
-		argv[1 + i++] = "-q";
+		argv[3 + i++] = "-q";
 	} else {
 		/* ssh(1) allows up to 3 "-v" options. */
 		for (i = 0; i < MIN(3, verbosity); i++)
-			argv[1 + i] = "-v";
+			argv[3 + i] = "-v";
 	}
-	argv[1 + i] = "--";
-	argv[2 + i] = (char *)host;
-	argv[3 + i] = (char *)cmd;
-	argv[4 + i] = (char *)path;
-	argv[5 + i] = NULL;
+	argv[3 + i] = "--";
+	argv[4 + i] = (char *)host;
+	argv[5 + i] = (char *)cmd;
+	argv[6 + i] = (char *)path;
+	argv[7 + i] = NULL;
 
 	if (pipe(pfd) == -1)
 		return got_error_from_errno("pipe");
@@ -146,6 +151,9 @@ dial_git(int *fetchfd, const char *host, const char *p
 
 	*fetchfd = -1;
 
+	if (port == NULL)
+		port = GOT_DEFAULT_GIT_PORT_STR;
+
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
@@ -238,11 +246,6 @@ got_fetch_parse_uri(char **proto, char **host, char **
 		/* Try parsing Git's "scp" style URL syntax. */
 		*proto = strdup("ssh");
 		if (proto == NULL) {
-			err = got_error_from_errno("strdup");
-			goto done;
-		}
-		*port = strdup("22");
-		if (*port == NULL) {
 			err = got_error_from_errno("strdup");
 			goto done;
 		}
@@ -296,10 +299,6 @@ got_fetch_parse_uri(char **proto, char **host, char **
 				err = got_error_from_errno("strndup");
 				goto done;
 			}
-			if (asprintf(port, "%u", GOT_DEFAULT_GIT_PORT) == -1) {
-				err = got_error_from_errno("asprintf");
-				goto done;
-			}
 		}
 	}
 
blob - 31b97a896df4896b127a7424821636148ccc8a8a
blob + 1d4429c2303caf6a1a577319457466d945db73ed
--- regress/fetch/fetch_test.c
+++ regress/fetch/fetch_test.c
@@ -83,23 +83,23 @@ fetch_parse_uri(void)
 		    NULL, NULL, NULL, NULL, NULL, GOT_ERR_PARSE_URI },
 
 		{ "git://127.0.0.1/git/myrepo",
-		    "git", "127.0.0.1", GOT_DEFAULT_GIT_PORT_STR,
+		    "git", "127.0.0.1", NULL,
 		    "/git/myrepo", "myrepo", GOT_ERR_OK },
 		{ "http://127.0.0.1/git/myrepo",
-		    "http", "127.0.0.1", GOT_DEFAULT_GIT_PORT_STR,
+		    "http", "127.0.0.1", NULL,
 		    "/git/myrepo", "myrepo", GOT_ERR_OK },
 		{ "gopher://127.0.0.1/git/myrepo",
-		    "gopher", "127.0.0.1", GOT_DEFAULT_GIT_PORT_STR,
+		    "gopher", "127.0.0.1", NULL,
 		    "/git/myrepo", "myrepo", GOT_ERR_OK },
 
 		{ "git://127.0.0.1:22/git/myrepo",
 		    "git", "127.0.0.1", "22", "/git/myrepo", "myrepo",
 		    GOT_ERR_OK },
 		{ "git://127.0.0.1/git/repos/foo/bar/myrepo.git",
-		    "git", "127.0.0.1", GOT_DEFAULT_GIT_PORT_STR,
+		    "git", "127.0.0.1", NULL,
 		    "/git/repos/foo/bar/myrepo.git", "myrepo", GOT_ERR_OK },
 		{ "https://127.0.0.1/git/repos/foo/../bar/myrepo.git",
-		    "https", "127.0.0.1", GOT_DEFAULT_GIT_PORT_STR,
+		    "https", "127.0.0.1", NULL,
 		    "/git/repos/foo/../bar/myrepo.git", "myrepo",
 		    GOT_ERR_OK },
 
@@ -111,13 +111,13 @@ fetch_parse_uri(void)
 		    GOT_ERR_OK },
 
 		{ "127.0.0.1:git/myrepo",
-		    "ssh", "127.0.0.1", "22", "git/myrepo", "myrepo",
+		    "ssh", "127.0.0.1", NULL, "git/myrepo", "myrepo",
 		    GOT_ERR_OK },
 		{ "127.0.0.1:/git/myrepo",
-		    "ssh", "127.0.0.1", "22", "/git/myrepo", "myrepo",
+		    "ssh", "127.0.0.1", NULL, "/git/myrepo", "myrepo",
 		    GOT_ERR_OK },
 		{ "127.0.0.1:22/git/myrepo",
-		    "ssh", "127.0.0.1", "22", "22/git/myrepo", "myrepo",
+		    "ssh", "127.0.0.1", NULL, "22/git/myrepo", "myrepo",
 		    GOT_ERR_OK },
 	};
 	int i;