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

Re: [PATCH] bundle-uri: do not die on unresolvable relative URIs

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 3, 2026, 13:04 UTC
Message-ID
<aunb6OjWKWLyl-mp@pks.im>
In-Reply-To
<20261028115818.410-1-aniketgupta3001@gmail.com>
On Wed, Oct 28, 2026 at 11:58:18AM +0000, Aniket Gupta wrote:
> relative_url() calls die() when the relative URL has more "../"
> components than the remote URL can absorb. bundle_list_update() calls
> it on URIs taken from a bundle list and a single bad entry takes down
> the whole command.
Which command?
> Add relative_url_gently() which returns NULL and records the reason in
> a strbuf instead of dying. This will keep relative_url() as a wrapper
s/will keep/keeps/. We're in present tense.
> that dies so the submodule callers are unchanged. Use the new function
> in bundle_list_update() and report the problem as an error like the
> other malformed lines in a bundle list.

These "bundle lists" are quite abstract here. It would help the reader if the commit message briefly mentioned where such a list even comes from.

Even more importantly though, do we now only print the error and then die or do we continue? And if the latter, why is it fine to continue even if we have failed to retrieve the bundle? And is it fine to continue for both callers of this function?

Show 6 quoted lines
> diff --git a/bundle-uri.c b/bundle-uri.c
> index 2bb2eb99e4..1f198ef9a9 100644
> --- a/bundle-uri.c
> +++ b/bundle-uri.c
> @@ -210,9 +210,17 @@ static int bundle_list_update(const char *key, const char *value,
>  	strbuf_release(&id);

Okay. The only other allocated variable was released already, so nothing that we'd have to do in that case.

Show 15 quoted lines
>  	if (!strcmp(subkey, "uri")) {
> +		struct strbuf err = STRBUF_INIT;
> +
>  		if (bundle->uri)
>  			return -1;
> -		bundle->uri = relative_url(list->baseURI, value, NULL);
> +		bundle->uri = relative_url_gently(list->baseURI, value, NULL,
> +						  &err);
> +		if (!bundle->uri) {
> +			error("%s", err.buf);
> +			strbuf_release(&err);
> +			return -1;
> +		}
>  		return 0;
>  	}

Looks reasonable. There's already other branches here that may return errors, so any caller that wouldn't know to hanlde such an error would already be broken right now.

Show 19 quoted lines
> diff --git a/remote.c b/remote.c
> index 49ee2ea318..7472c426aa 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -3073,8 +3077,16 @@ char *relative_url(const char *remote_url, const char *url,
>  	 */
>  	while (*url) {
>  		if (starts_with_dot_dot_slash_native(url)) {
> +			int chopped;
> +
>  			url += 3;
> -			colonsep |= chop_last_dir(&remoteurl, is_relative);
> +			chopped = chop_last_dir(&remoteurl, is_relative, err);
> +			if (chopped < 0) {
> +				free(remoteurl);
> +				strbuf_release(&sb);
> +				return NULL;
> +			}
> +			colonsep |= chopped;

The error handling does get a bit unwieldy in this function by now. It would have been great to maybe add a preparatory commit where we adapt it to have a single unified exit path that releases memory. But I won't insist on it.

Show 10 quoted lines
> diff --git a/t/t5750-bundle-uri-parse.sh b/t/t5750-bundle-uri-parse.sh
> index 70ae94c4d0..0f0ac29565 100755
> --- a/t/t5750-bundle-uri-parse.sh
> +++ b/t/t5750-bundle-uri-parse.sh
> @@ -68,17 +68,16 @@ test_expect_success 'bundle_uri_parse_line(): relative URIs and parent paths' '
>  		uri = <uri>/bundle.bdl
>  	[bundle "two"]
>  		uri = bundle.bdl
> -	[bundle "three"]
> -		uri = <uri>/../bundle.bdl

Why do we have to drop these lines here? Interestingly, we don't seem to use this file at all in this test.

Show 9 quoted lines
>  	EOF
>  
> -	# TODO: We would prefer if parsing a bundle list would not cause
> -	# a die() and instead would give a warning and allow the rest of
> -	# a Git command to continue. This test_must_fail is necessary for
> -	# now until the interface for relative_url() allows for reporting
> -	# an error instead of die()ing.
> +	cat >err.expect <<-\EOF &&
> +	error: cannot strip one component off url '\''.'\''

This error message doesn't really look useful to me. In the current form the user wouldn't be able to figure out which URL specifically we failed to strip. It's a preexisting issue, true, but do we maybe want to fix it while at it?

Thanks!
Patrick
Previous: Aniket GuptaNext: Aniket Gupta
Message 2 of 6 in “bundle-uri: do not die on unresolvable relative URIs”
  1. bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Oct 28, 2026
  2. Patrick SteinhardtNov 3, 2026
  3. Aniket GuptaNov 3, 2026
  4. bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 3, 2026
  5. Patrick SteinhardtNov 5, 2026
  6. Aniket GuptaNov 5, 2026

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.