Commit 09838ffc9388f0cdbc316deb5eaae54ec4841207

Stefan Sperling 2020-03-18T16:11:26

make got_fetch() expect URI information in parsed form

diff --git a/got/got.c b/got/got.c
index d5f868e..2aa285a 100644
--- a/got/got.c
+++ b/got/got.c
@@ -971,7 +971,9 @@ done:
 static const struct got_error *
 cmd_clone(int argc, char *argv[])
 {
-	char *uri, *branch_filter, *dirname;
+	const struct got_error *err = NULL;
+	const char *uri, *branch_filter, *dirname;
+	char *proto, *host, *port, *repo_name, *server_path;
 	int ch;
 
 	while ((ch = getopt(argc, argv, "b:")) != -1) {
@@ -993,7 +995,21 @@ cmd_clone(int argc, char *argv[])
 		dirname = argv[1];
 	else
 		usage_clone();
-	return got_fetch(argv[0], branch_filter, dirname);
+
+	err = got_fetch_parse_uri(&proto, &host, &port, &server_path,
+	    &repo_name, argv[0]);
+	if (err)
+		goto done;
+
+	err = got_fetch(proto, host, port, server_path, repo_name,
+	    branch_filter, dirname);
+done:
+	free(proto);
+	free(host);
+	free(port);
+	free(server_path);
+	free(repo_name);
+	return err;
 }
 
 static const struct got_error *
diff --git a/include/got_fetch.h b/include/got_fetch.h
index 33820f9..3af0abb 100644
--- a/include/got_fetch.h
+++ b/include/got_fetch.h
@@ -20,4 +20,6 @@
 
 const struct got_error *got_fetch_parse_uri(char **, char **, char **,
     char **, char **, const char *);
-const struct got_error* got_fetch(char *, char *, char *);
+const struct got_error *got_fetch(const char *, const char *,
+    const char *, const char *, const char *, const char *,
+    const char *);
diff --git a/lib/fetch.c b/lib/fetch.c
index b4ee27f..ff27135 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -82,7 +82,8 @@ hassuffix(char *base, char *suf)
 }
 
 static const struct got_error *
-dial_ssh(int *fetchfd, char *host, char *port, char *path, char *direction)
+dial_ssh(int *fetchfd, const char *host, const char *port, const char *path,
+    const char *direction)
 {
 	const struct got_error *error = NULL;
 	int pid, pfd[2];
@@ -118,7 +119,8 @@ dial_ssh(int *fetchfd, char *host, char *port, char *path, char *direction)
 }
 
 static const struct got_error *
-dial_git(int *fetchfd, char *host, char *port, char *path, char *direction)
+dial_git(int *fetchfd, const char *host, const char *port, const char *path,
+    const char *direction)
 {
 	const struct got_error *err = NULL;
 	struct addrinfo hints, *servinfo, *p;
@@ -277,9 +279,10 @@ done:
 }
 
 const struct got_error*
-got_fetch(char *uri, char *branch_filter, char *destdir)
+got_fetch(const char *proto, const char *host, const char *port,
+    const char *server_path, const char *repo_name,
+    const char *branch_filter, const char *destdir)
 {
-	char *proto, *host, *port, *repo_name, *server_path;
 	int imsg_fetchfds[2], imsg_idxfds[2], fetchfd = -1;
 	int packfd = -1, npackfd = -1, idxfd = -1, nidxfd = -1;
 	int status, done = 0;
@@ -298,10 +301,6 @@ got_fetch(char *uri, char *branch_filter, char *destdir)
 	TAILQ_INIT(&symrefs);
 
 	fetchfd = -1;
-	err = got_fetch_parse_uri(&proto, &host, &port, &server_path,
-	    &repo_name, uri);
-	if (err)
-		return err;
 	if (destdir == NULL) {
 		if (asprintf(&default_destdir, "%s.git", repo_name) == -1)
 			return got_error_from_errno("asprintf");