From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: tboegi@web.de, "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/2] config: resolve symlinks in conditional include's patterns
Date: Thu, 30 Mar 2017 18:37:23 +0700 [thread overview]
Message-ID: <20170330113723.20474-2-pclouds@gmail.com> (raw)
In-Reply-To: <20170330113723.20474-1-pclouds@gmail.com>
$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.
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);
--
2.11.0.157.gd943d85
next prev parent reply other threads:[~2017-03-30 11:37 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 ` Nguyễn Thái Ngọc Duy [this message]
2017-03-30 18:38 ` [PATCH 2/2] config: resolve symlinks in conditional include's patterns Junio C Hamano
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=20170330113723.20474-2-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).