]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: allow relative_url() to return an absolute url
authorDerrick Stolee <derrickstolee@github.com>
Mon, 16 May 2022 20:11:04 +0000 (20:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2022 22:02:10 +0000 (15:02 -0700)
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>
remote.c
remote.h

index 87656138645e925ade1e72794b59217c33a9047c..7576f673fcdc0d2e3f9b661b99e9164c5d09bd99 100644 (file)
--- 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';
 
index f18fd27e530a90f40527a4e873e08172ed39f373..dd4402436f1f2e1bb06d37c932ca8f9e3afcf48a 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -434,6 +434,7 @@ void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
  * http://a.com/b  ../../../c       http:/c          error out
  * http://a.com/b  ../../../../c    http:c           error out
  * http://a.com/b  ../../../../../c    .:c           error out
+ * http://a.com/b  http://d.org/e   http://d.org/e   as is
  * NEEDSWORK: Given how chop_last_dir() works, this function is broken
  * when a local part has a colon in its path component, too.
  */