make got_fetch() expect URI information in parsed form
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
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");