Skip to content

Commit 834e352

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d04e71 commit 834e352

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

remote.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,10 +2761,18 @@ char *relative_url(const char *remote_url, const char *url,
27612761
int is_relative = 0;
27622762
int colonsep = 0;
27632763
char *out;
2764-
char *remoteurl = xstrdup(remote_url);
2764+
char *remoteurl;
27652765
struct strbuf sb = STRBUF_INIT;
2766-
size_t len = strlen(remoteurl);
2766+
size_t len;
2767+
2768+
if (!url_is_local_not_ssh(url) || is_absolute_path(url))
2769+
return xstrdup(url);
2770+
2771+
len = strlen(remote_url);
2772+
if (!len)
2773+
BUG("invalid empty remote_url");
27672774

2775+
remoteurl = xstrdup(remote_url);
27682776
if (is_dir_sep(remoteurl[len-1]))
27692777
remoteurl[len-1] = '\0';
27702778

remote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
434434
* http://a.com/b ../../../c http:/c error out
435435
* http://a.com/b ../../../../c http:c error out
436436
* http://a.com/b ../../../../../c .:c error out
437+
* http://a.com/b http://d.org/e http://d.org/e as is
437438
* NEEDSWORK: Given how chop_last_dir() works, this function is broken
438439
* when a local part has a colon in its path component, too.
439440
*/

0 commit comments

Comments
 (0)