From 4a2d5ae262a6d372d0951da9cee3c7ad2a8dbca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 26 Oct 2013 09:09:20 +0700 Subject: pathspec: stop --*-pathspecs impact on internal parse_pathspec() uses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normally parse_pathspec() is used on command line arguments where it can do fancy thing like parsing magic on each argument or adding magic for all pathspecs based on --*-pathspecs options. There's another use of parse_pathspec(), where pathspec is needed, but the input is known to be pure paths. In this case we usually don't want --*-pathspecs to interfere. And we definitely do not want to parse magic in these paths, regardless of --literal-pathspecs. Add new flag PATHSPEC_LITERAL_PATH for this purpose. When it's set, --*-pathspecs are ignored, no magic is parsed. And if the caller allows PATHSPEC_LITERAL (i.e. the next calls can take literal magic), then PATHSPEC_LITERAL will be set. This fixes cases where git chokes when GIT_*_PATHSPECS are set because parse_pathspec() indicates it won't take any magic. But GIT_*_PATHSPECS add them anyway. These are export GIT_LITERAL_PATHSPECS=1 git blame -- something git log --follow something git log --merge "git ls-files --with-tree=path" (aka parse_pathspec() in overlay_tree_on_cache()) is safe because the input is empty, and producing one pathspec due to PATHSPEC_PREFER_CWD does not take any magic into account. Signed-off-by: Nguyễn Thái Ngọc Duy Acked-by: Jeff King Signed-off-by: Junio C Hamano --- pathspec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pathspec.c') diff --git a/pathspec.c b/pathspec.c index ad1a9f5b2..4cf2bd365 100644 --- a/pathspec.c +++ b/pathspec.c @@ -128,7 +128,11 @@ static unsigned prefix_pathspec(struct pathspec_item *item, die(_("global 'literal' pathspec setting is incompatible " "with all other global pathspec settings")); - if (elt[0] != ':' || literal_global) { + if (flags & PATHSPEC_LITERAL_PATH) + global_magic = 0; + + if (elt[0] != ':' || literal_global || + (flags & PATHSPEC_LITERAL_PATH)) { ; /* nothing to do */ } else if (elt[1] == '(') { /* longhand */ @@ -405,6 +409,9 @@ void parse_pathspec(struct pathspec *pathspec, item[i].magic = prefix_pathspec(item + i, &short_magic, argv + i, flags, prefix, prefixlen, entry); + if ((flags & PATHSPEC_LITERAL_PATH) && + !(magic_mask & PATHSPEC_LITERAL)) + item[i].magic |= PATHSPEC_LITERAL; if (item[i].magic & magic_mask) unsupported_magic(entry, item[i].magic & magic_mask, -- cgit v1.2.1