git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/8] remote: allow relative_url() to return an absolute url

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
May 16, 2022, 20:11 UTC
Message-ID
<d73b578e990c37781ea50e13d00f5385400e81ad.1652731865.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1233.git.1652731865.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

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>
---
 remote.c | 12 ++++++++++--
 remote.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index 87656138645..7576f673fcd 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';
 
diff --git a/remote.h b/remote.h
index f18fd27e530..dd4402436f1 100644
--- 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.
  */
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Ævar Arnfjörð Bjarmason via GitGitGadget
Message 8 of 9 in “Bundle URIs: Prepatory patches”
  1. 0/8 Bundle URIs: Prepatory patchesDerrick Stolee via GitGitGadget, May 16, 2022
  2. 1/8 connect.c: refactor sending of agent & object-formatÆvar Arnfjörð Bjarmason via GitGitGadget, May 16, 2022
  3. 2/8 dir API: add a generalized path_match_flags() functionÆvar Arnfjörð Bjarmason via GitGitGadget, May 16, 2022
  4. 3/8 fetch-pack: add a deref_without_lazy_fetch_extended()Ævar Arnfjörð Bjarmason via GitGitGadget, May 16, 2022
  5. 4/8 fetch-pack: move --keep=* option filling to a functionÆvar Arnfjörð Bjarmason via GitGitGadget, May 16, 2022
  6. 5/8 http: make http_get_file() externalDerrick Stolee via GitGitGadget, May 16, 2022
  7. 6/8 remote: move relative_url()Derrick Stolee via GitGitGadget, May 16, 2022
  8. 7/8 remote: allow relative_url() to return an absolute urlDerrick Stolee via GitGitGadget, May 16, 2022
  9. 8/8 bundle.h: make "fd" version of read_bundle_header() publicÆvar Arnfjörð Bjarmason via GitGitGadget, May 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.