summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fetchhead.c38
-rw-r--r--src/netops.c29
-rw-r--r--src/netops.h3
3 files changed, 67 insertions, 3 deletions
diff --git a/src/fetchhead.c b/src/fetchhead.c
index bdded029a..5dd82fc76 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -13,6 +13,7 @@
#include "buffer.h"
#include "fileops.h"
#include "filebuf.h"
+#include "netops.h"
#include "refs.h"
#include "repository.h"
@@ -36,6 +37,33 @@ int git_fetchhead_ref_cmp(const void *a, const void *b)
return 0;
}
+static char *sanitized_remote_url(const char *remote_url)
+{
+ gitno_connection_data url = {0};
+ char *sanitized = NULL;
+ int error;
+
+ if (gitno_connection_data_from_url(&url, remote_url, NULL) == 0) {
+ git_buf buf = GIT_BUF_INIT;
+
+ git__free(url.user);
+ git__free(url.pass);
+ url.user = url.pass = NULL;
+
+ if ((error = gitno_connection_data_fmt(&buf, &url)) < 0)
+ goto fallback;
+
+ sanitized = git_buf_detach(&buf);
+ }
+
+fallback:
+ if (!sanitized)
+ sanitized = git__strdup(remote_url);
+
+ gitno_connection_data_free_ptrs(&url);
+ return sanitized;
+}
+
int git_fetchhead_ref_create(
git_fetchhead_ref **out,
git_oid *oid,
@@ -57,11 +85,15 @@ int git_fetchhead_ref_create(
git_oid_cpy(&fetchhead_ref->oid, oid);
fetchhead_ref->is_merge = is_merge;
- if (ref_name)
+ if (ref_name) {
fetchhead_ref->ref_name = git__strdup(ref_name);
+ GIT_ERROR_CHECK_ALLOC(fetchhead_ref->ref_name);
+ }
- if (remote_url)
- fetchhead_ref->remote_url = git__strdup(remote_url);
+ if (remote_url) {
+ fetchhead_ref->remote_url = sanitized_remote_url(remote_url);
+ GIT_ERROR_CHECK_ALLOC(fetchhead_ref->remote_url);
+ }
*out = fetchhead_ref;
diff --git a/src/netops.c b/src/netops.c
index ecbc2aebe..f63ff380a 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -206,6 +206,35 @@ cleanup:
return error;
}
+int gitno_connection_data_fmt(git_buf *buf, gitno_connection_data *d)
+{
+ if (d->host) {
+ git_buf_puts(buf, d->use_ssl ? prefix_https : prefix_http);
+
+ if (d->user) {
+ git_buf_puts(buf, d->user);
+
+ if (d->pass) {
+ git_buf_puts(buf, ":");
+ git_buf_puts(buf, d->pass);
+ }
+
+ git_buf_putc(buf, '@');
+ }
+
+ git_buf_puts(buf, d->host);
+
+ if (d->port && strcmp(d->port, gitno__default_port(d))) {
+ git_buf_putc(buf, ':');
+ git_buf_puts(buf, d->port);
+ }
+ }
+
+ git_buf_puts(buf, d->path ? d->path : "/");
+
+ return git_buf_oom(buf) ? -1 : 0;
+}
+
void gitno_connection_data_free_ptrs(gitno_connection_data *d)
{
git__free(d->host); d->host = NULL;
diff --git a/src/netops.h b/src/netops.h
index f376bd911..fcdbccf0d 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -84,6 +84,9 @@ int gitno_connection_data_from_url(
const char *url,
const char *service_suffix);
+/* Format a URL into a buffer */
+int gitno_connection_data_fmt(git_buf *buf, gitno_connection_data *data);
+
/* This frees all the pointers IN the struct, but not the struct itself. */
void gitno_connection_data_free_ptrs(gitno_connection_data *data);