aboutsummaryrefslogtreecommitdiffstats
path: root/remote.c
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-05-16 20:11:04 +0000
committerJunio C Hamano <gitster@pobox.com>2022-05-16 15:02:10 -0700
commit834e3520ab6435073ef58922b24d732f96cdf461 (patch)
tree3785be3bd77fd6d883ceff57d789e6f1502ef1d3 /remote.c
parent1d04e719e7bda885991cd4566a5bb6f6565fa106 (diff)
downloadgit-834e3520ab6435073ef58922b24d732f96cdf461.tar.gz
remote: allow relative_url() to return an absolute url
When the 'url' parameter was absolute, the previous implementation would concatenate 'remote_url' with 'url'. Instead, we want to return 'url' in this case. The documentation now discusses what happens when supplying two absolute URLs. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/remote.c b/remote.c
index 8765613864..7576f673fc 100644
--- a/remote.c
+++ b/remote.c
@@ -2761,10 +2761,18 @@ char *relative_url(const char *remote_url, const char *url,
int is_relative = 0;
int colonsep = 0;
char *out;
- char *remoteurl = xstrdup(remote_url);
+ char *remoteurl;
struct strbuf sb = STRBUF_INIT;
- size_t len = strlen(remoteurl);
+ size_t len;
+
+ if (!url_is_local_not_ssh(url) || is_absolute_path(url))
+ return xstrdup(url);
+
+ len = strlen(remote_url);
+ if (!len)
+ BUG("invalid empty remote_url");
+ remoteurl = xstrdup(remote_url);
if (is_dir_sep(remoteurl[len-1]))
remoteurl[len-1] = '\0';