All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, tboegi@web.de
Subject: Re: [PATCH 2/2] config: resolve symlinks in conditional include's patterns
Date: Thu, 30 Mar 2017 11:38:44 -0700	[thread overview]
Message-ID: <xmqqinmq4nkb.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170330113723.20474-2-pclouds@gmail.com> (=?utf-8?B?Ik5n?= =?utf-8?B?dXnhu4VuIFRow6FpIE5n4buNYw==?= Duy"'s message of "Thu, 30 Mar 2017 18:37:23 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> $GIT_DIR returned by get_git_dir() is normalized, with all symlinks
> resolved (see setup_work_tree function). In order to match paths (or
> patterns) against $GIT_DIR char-by-char, they have to be normalized
> too. There is a note in config.txt about this, that the user need to
> resolve symlinks by themselves if needed.
>
> The problem is, we allow certain path expansion, '~/' and './', for
> convenience and can't ask the user to resolve symlinks in these
> expansions. Make sure the expanded paths have all symlinks resolved.

That sounds sensible but I fail to see why 1/2 is the right approach
to do this, and I must be missing something.  Wouldn't you get the
same result if you run realpath() yourself on expanded, after
receiving the return value of expand_user_path() in it?

Can you add a test to demonstrate the issue (which would need to be
protected with SYMLINKS prereq)?

Thanks.

> PS. The strbuf_realpath(&text, get_git_dir(), 1) is still needed because
> get_git_dir() may return relative path.
>
> Noticed-by: Torsten Bögershausen <tboegi@web.de>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  config.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/config.c b/config.c
> index f036c721e6..d5ba848b65 100644
> --- a/config.c
> +++ b/config.c
> @@ -177,7 +177,7 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
>  	char *expanded;
>  	int prefix = 0;
>  
> -	expanded = expand_user_path(pat->buf, 0);
> +	expanded = expand_user_path(pat->buf, 1);
>  	if (expanded) {
>  		strbuf_reset(pat);
>  		strbuf_addstr(pat, expanded);
> @@ -191,7 +191,7 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
>  			return error(_("relative config include "
>  				       "conditionals must come from files"));
>  
> -		strbuf_add_absolute_path(&path, cf->path);
> +		strbuf_realpath(&path, cf->path, 1);
>  		slash = find_last_dir_sep(path.buf);
>  		if (!slash)
>  			die("BUG: how is this possible?");
> @@ -213,7 +213,7 @@ static int include_by_gitdir(const char *cond, size_t cond_len, int icase)
>  	struct strbuf pattern = STRBUF_INIT;
>  	int ret = 0, prefix;
>  
> -	strbuf_add_absolute_path(&text, get_git_dir());
> +	strbuf_realpath(&text, get_git_dir(), 1);
>  	strbuf_add(&pattern, cond, cond_len);
>  	prefix = prepare_include_condition_pattern(&pattern);

  reply	other threads:[~2017-03-30 18:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-25 10:46 t1503 broken ? Torsten Bögershausen
2017-03-25 11:46 ` Duy Nguyen
2017-03-25 12:26   ` Duy Nguyen
2017-03-25 13:05     ` Duy Nguyen
2017-03-25 19:41       ` Torsten Bögershausen
2017-03-30 11:37       ` [PATCH 1/2] path.c: and an option to call real_path() in expand_user_path() Nguyễn Thái Ngọc Duy
2017-03-30 11:37         ` [PATCH 2/2] config: resolve symlinks in conditional include's patterns Nguyễn Thái Ngọc Duy
2017-03-30 18:38           ` Junio C Hamano [this message]
2017-04-04 10:12             ` Duy Nguyen
2017-04-05 10:24         ` [PATCH v2 1/2] path.c: and an option to call real_path() in expand_user_path() Nguyễn Thái Ngọc Duy
2017-04-05 10:24           ` [PATCH v2 2/2] config: resolve symlinks in conditional include's patterns Nguyễn Thái Ngọc Duy

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=xmqqinmq4nkb.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=tboegi@web.de \
    /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.