summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-12-19 11:33:56 -0800
committerJunio C Hamano <gitster@pobox.com>2017-12-19 11:33:56 -0800
commitf4f233e13daa584e5178141eb10e6e9527a3454c (patch)
tree2705e845567749c51ba409d303502f5d4e576188
parentd7c6c2369ac21141b7c6cceaebc6414ec3da14ad (diff)
parenteef3df5a93784e4d709907ce03006374ffc3ea26 (diff)
downloadgit-f4f233e13daa584e5178141eb10e6e9527a3454c.tar.gz
Merge branch 'bw/pathspec-match-submodule-boundary'
An v2.12-era regression in pathspec match logic, which made it look into submodule tree even when it is not desired, has been fixed. * bw/pathspec-match-submodule-boundary: pathspec: only match across submodule boundaries when requested
-rw-r--r--builtin/grep.c1
-rw-r--r--pathspec.h1
-rwxr-xr-xt/t4208-log-magic-pathspec.sh19
-rw-r--r--tree-walk.c5
4 files changed, 24 insertions, 2 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 5a6cfe6b45..3ca4ac80d8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1015,6 +1015,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
prefix, argv + i);
pathspec.max_depth = opt.max_depth;
pathspec.recursive = 1;
+ pathspec.recurse_submodules = !!recurse_submodules;
#ifndef NO_PTHREADS
if (list.nr || cached || show_in_pager)
diff --git a/pathspec.h b/pathspec.h
index 6420d1080a..099a170c2e 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -24,6 +24,7 @@ struct pathspec {
int nr;
unsigned int has_wildcard:1;
unsigned int recursive:1;
+ unsigned int recurse_submodules:1;
unsigned magic;
int max_depth;
struct pathspec_item {
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 935df6a65c..a1705f70cf 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -93,4 +93,23 @@ test_expect_success 'command line pathspec parsing for "git log"' '
git log --merge -- a
'
+test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
+ test_when_finished "rm -rf repo submodule" &&
+ git init submodule &&
+ test_commit -C submodule initial &&
+ git init repo &&
+ >"repo/[bracket]" &&
+ git -C repo add "[bracket]" &&
+ test_tick &&
+ git -C repo commit -m bracket &&
+ git -C repo rev-list HEAD -- "[bracket]" >expect &&
+
+ git -C repo submodule add ../submodule &&
+ test_tick &&
+ git -C repo commit -m submodule &&
+
+ git -C repo rev-list HEAD -- "[bracket]" >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/tree-walk.c b/tree-walk.c
index 684f0e3373..63a87ed666 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1011,7 +1011,8 @@ static enum interesting do_match(const struct name_entry *entry,
* character. More accurate matching can then
* be performed in the submodule itself.
*/
- if (ps->recursive && S_ISGITLINK(entry->mode) &&
+ if (ps->recurse_submodules &&
+ S_ISGITLINK(entry->mode) &&
!ps_strncmp(item, match + baselen,
entry->path,
item->nowildcard_len - baselen))
@@ -1060,7 +1061,7 @@ match_wildcards:
* character. More accurate matching can then
* be performed in the submodule itself.
*/
- if (ps->recursive && S_ISGITLINK(entry->mode) &&
+ if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
!ps_strncmp(item, match, base->buf + base_offset,
item->nowildcard_len)) {
strbuf_setlen(base, base_offset + baselen);