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

Re: [PATCH 1/2] submodule: port resolve_relative_url from shell to C

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 18, 2016, 20:23 UTC
Message-ID
<xmqqsi0pg439.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1455320356-15778-2-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 60 quoted lines
> +static int starts_with_dot_slash(const char *str)
> +{
> +	return str[0] == '.' && is_dir_sep(str[1]);
> +}
> +
> +static int starts_with_dot_dot_slash(const char *str)
> +{
> +	return str[0] == '.' && str[1] == '.' && is_dir_sep(str[2]);
> +}
> +
> +/*
> + * Returns 1 if it was the last chop before ':'.
> + */
> +static int chop_last_dir(char **remoteurl, int is_relative)
> +{
> +	char *rfind = find_last_dir_sep(*remoteurl);
> +	if (rfind) {
> +		*rfind = '\0';
> +		return 0;
> +	}
> +
> +	rfind = strrchr(*remoteurl, ':');
> +	if (rfind) {
> +		*rfind = '\0';
> +		return 1;
> +	}
> +
> +	if (is_relative || !strcmp(".", *remoteurl))
> +		die(_("cannot strip one component off url '%s'"),
> +			*remoteurl);
> +
> +	free(*remoteurl);
> +	*remoteurl = xstrdup(".");
> +	return 0;
> +}
> +
> +/*
> + * The `url` argument is the URL that navigates to the submodule origin
> + * repo. When relative, this URL is relative to the superproject origin
> + * URL repo. The `up_path` argument, if specified, is the relative
> + * path that navigates from the submodule working tree to the superproject
> + * working tree. Returns the origin URL of the submodule.
> + *
> + * Return either an absolute URL or filesystem path (if the superproject
> + * origin URL is an absolute URL or filesystem path, respectively) or a
> + * relative file system path (if the superproject origin URL is a relative
> + * file system path).
> + *
> + * When the output is a relative file system path, the path is either
> + * relative to the submodule working tree, if up_path is specified, or to
> + * the superproject working tree otherwise.
> + *
> + * NEEDSWORK: This works incorrectly on the domain and protocol part.
> + * remote_url      url              outcome          correct
> + * http://a.com/b  ../c             http://a.com/c   yes
> + * http://a.com/b  ../../c          http://c         no (domain should be kept)
> + * http://a.com/b  ../../../c       http:/c          no
> + * http://a.com/b  ../../../../c    http:c           no
> + * http://a.com/b  ../../../../../c    .:c           no
> + */

Not just "no" but we should say what the expected outcome is. I think all of them should error out?

Given how chop_last_dir() works, I think this function is broken when a local part has a colon in its path component, too. I do not think the scripted version did any better on such a URL; just another thing that NEEDSWORK comment should list as a thing to be fixed in the future.

Previous: Stefan BellerNext: Duy Nguyen
Message 3 of 9 in “Port `git submodule init` from shell to C”
  1. 0/2 Port `git submodule init` from shell to CStefan Beller, Feb 12, 2016
  2. 1/2 submodule: port resolve_relative_url from shell to CStefan Beller, Feb 12, 2016
  3. Junio C HamanoFeb 18, 2016
  4. Duy NguyenFeb 27, 2016
  5. Johannes SixtMar 2, 2016
  6. Stefan BellerMar 2, 2016
  7. 2/2 submodule: port init from shell to CStefan Beller, Feb 12, 2016
  8. Junio C HamanoFeb 18, 2016
  9. Junio C HamanoFeb 18, 2016

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.