summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Nguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-10-26 09:09:20 +0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-10-28 09:57:36 -0700
commit4a2d5ae262a6d372d0951da9cee3c7ad2a8dbca6 (patch)
tree39fdf613b7433228f10a0ac613b3cfd9e14a760b
parentUpdate draft release notes to 1.8.5 (diff)
downloadtgif-4a2d5ae262a6d372d0951da9cee3c7ad2a8dbca6.tar.xz
pathspec: stop --*-pathspecs impact on internal parse_pathspec() uses
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 <pclouds@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/blame.c4
-rw-r--r--pathspec.c9
-rw-r--r--pathspec.h7
-rw-r--r--revision.c3
-rwxr-xr-xt/t6130-pathspec-noglob.sh7
-rw-r--r--tree-diff.c4
6 files changed, 30 insertions, 4 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 6da7233968..1407ae7eb2 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -409,7 +409,9 @@ static struct origin *find_origin(struct scoreboard *sb,
paths[0] = origin->path;
paths[1] = NULL;
- parse_pathspec(&diff_opts.pathspec, PATHSPEC_ALL_MAGIC, 0, "", paths);
+ parse_pathspec(&diff_opts.pathspec,
+ PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
+ PATHSPEC_LITERAL_PATH, "", paths);
diff_setup_done(&diff_opts);
if (is_null_sha1(origin->commit->object.sha1))
diff --git a/pathspec.c b/pathspec.c
index ad1a9f5b28..4cf2bd365a 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,
diff --git a/pathspec.h b/pathspec.h
index 944baeb622..a75e9242d1 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -58,6 +58,13 @@ struct pathspec {
#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5)
#define PATHSPEC_PREFIX_ORIGIN (1<<6)
#define PATHSPEC_KEEP_ORDER (1<<7)
+/*
+ * For the callers that just need pure paths from somewhere else, not
+ * from command line. Global --*-pathspecs options are ignored. No
+ * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is
+ * allowed, then it will automatically set for every pathspec.
+ */
+#define PATHSPEC_LITERAL_PATH (1<<8)
extern void parse_pathspec(struct pathspec *pathspec,
unsigned magic_mask,
diff --git a/revision.c b/revision.c
index 0173e0148b..9b9e22ee45 100644
--- a/revision.c
+++ b/revision.c
@@ -1372,7 +1372,8 @@ static void prepare_show_merge(struct rev_info *revs)
i++;
}
free_pathspec(&revs->prune_data);
- parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
+ parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
+ PATHSPEC_LITERAL_PATH, "", prune);
revs->limited = 1;
}
diff --git a/t/t6130-pathspec-noglob.sh b/t/t6130-pathspec-noglob.sh
index ea00d71e77..658353277e 100755
--- a/t/t6130-pathspec-noglob.sh
+++ b/t/t6130-pathspec-noglob.sh
@@ -108,6 +108,13 @@ test_expect_success 'no-glob environment variable works' '
test_cmp expect actual
'
+test_expect_success 'blame takes global pathspec flags' '
+ git --literal-pathspecs blame -- foo &&
+ git --icase-pathspecs blame -- foo &&
+ git --glob-pathspecs blame -- foo &&
+ git --noglob-pathspecs blame -- foo
+'
+
test_expect_success 'setup xxx/bar' '
mkdir xxx &&
test_commit xxx xxx/bar
diff --git a/tree-diff.c b/tree-diff.c
index ccf9d7c8fd..456660c7a2 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -254,7 +254,9 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
path[0] = p->one->path;
path[1] = NULL;
free_pathspec(&opt->pathspec);
- parse_pathspec(&opt->pathspec, PATHSPEC_ALL_MAGIC, 0, "", path);
+ parse_pathspec(&opt->pathspec,
+ PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
+ PATHSPEC_LITERAL_PATH, "", path);
/*
* The caller expects us to return a set of vanilla