summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-01 20:30:59 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-01 20:40:27 -0400
commitf89dc917d7cb1504b651fdb58c96397b3081a80d (patch)
treec490e3f5dc18caf88f97e06cc6c75ab3ede70310
parent9e98e443ca5e95bfb570536187c6e155bc126e59 (diff)
downloadlibgit2-f89dc917d7cb1504b651fdb58c96397b3081a80d.tar.gz
url: introduce `git_net_url_dup`
-rw-r--r--src/net.c40
-rw-r--r--src/net.h3
2 files changed, 43 insertions, 0 deletions
diff --git a/src/net.c b/src/net.c
index 3322f68c2..a685e4893 100644
--- a/src/net.c
+++ b/src/net.c
@@ -35,6 +35,46 @@ static const char *default_port_for_scheme(const char *scheme)
return NULL;
}
+int git_net_url_dup(git_net_url *out, git_net_url *in)
+{
+ if (in->scheme) {
+ out->scheme = git__strdup(in->scheme);
+ GIT_ERROR_CHECK_ALLOC(out->scheme);
+ }
+
+ if (in->host) {
+ out->host = git__strdup(in->host);
+ GIT_ERROR_CHECK_ALLOC(out->host);
+ }
+
+ if (in->port) {
+ out->port = git__strdup(in->port);
+ GIT_ERROR_CHECK_ALLOC(out->port);
+ }
+
+ if (in->path) {
+ out->path = git__strdup(in->path);
+ GIT_ERROR_CHECK_ALLOC(out->path);
+ }
+
+ if (in->query) {
+ out->query = git__strdup(in->query);
+ GIT_ERROR_CHECK_ALLOC(out->query);
+ }
+
+ if (in->username) {
+ out->username = git__strdup(in->username);
+ GIT_ERROR_CHECK_ALLOC(out->username);
+ }
+
+ if (in->password) {
+ out->password = git__strdup(in->password);
+ GIT_ERROR_CHECK_ALLOC(out->password);
+ }
+
+ return 0;
+}
+
int git_net_url_parse(git_net_url *url, const char *given)
{
struct http_parser_url u = {0};
diff --git a/src/net.h b/src/net.h
index 971e002b6..322d0bda9 100644
--- a/src/net.h
+++ b/src/net.h
@@ -21,6 +21,9 @@ typedef struct git_net_url {
#define GIT_NET_URL_INIT { NULL }
+/** Duplicate a URL */
+extern int git_net_url_dup(git_net_url *out, git_net_url *in);
+
/** Parses a string containing a URL into a structure. */
extern int git_net_url_parse(git_net_url *url, const char *str);