All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, jrnieder@gmail.com, Jens.Lehmann@web.de
Subject: Re: [PATCH 1/2] submodule: port resolve_relative_url from shell to C
Date: Thu, 18 Feb 2016 12:23:38 -0800	[thread overview]
Message-ID: <xmqqsi0pg439.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1455320356-15778-2-git-send-email-sbeller@google.com> (Stefan Beller's message of "Fri, 12 Feb 2016 15:39:15 -0800")

Stefan Beller <sbeller@google.com> writes:

> +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.

  reply	other threads:[~2016-02-18 20:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 23:39 [PATCH 0/2] Port `git submodule init` from shell to C Stefan Beller
2016-02-12 23:39 ` [PATCH 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-02-18 20:23   ` Junio C Hamano [this message]
2016-02-27  8:28   ` Duy Nguyen
2016-03-02 17:21   ` Johannes Sixt
2016-03-02 17:34     ` Stefan Beller
2016-02-12 23:39 ` [PATCH 2/2] submodule: port init " Stefan Beller
2016-02-18 20:46   ` Junio C Hamano
2016-02-18 23:15     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2016-04-16  0:50 [PATCH 0/2] Another reroll of sb/submodule-init Stefan Beller
2016-04-16  0:50 ` [PATCH 1/2] submodule: port resolve_relative_url from shell to C Stefan Beller
2016-04-14 18:18 [PATCH 0/2] Port `submodule init` " Stefan Beller
2016-04-14 18:18 ` [PATCH 1/2] submodule: port resolve_relative_url from shell " Stefan Beller
2016-04-14 19:35   ` Johannes Sixt
2016-04-14 19:37     ` Stefan Beller
2016-04-13  0:18 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-04-13  0:18 ` [PATCH 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-03-15  0:15 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-03-15  0:15 ` [PATCH 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-01-15 23:37 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-01-15 23:37 ` [PATCH 1/2] submodule: Port resolve_relative_url " Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqsi0pg439.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.