summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-10-27 12:54:05 -0700
committerJunio C Hamano <gitster@pobox.com>2014-10-27 12:54:05 -0700
commit2e50bf575fbaaf3b0410ae9af0c1ab6af691aa9c (patch)
tree540aae001774c52ace3c59477a3cb313b6476bad
parentd5a7410d22075ecf9f2597d2516bb9914cd55049 (diff)
downloadgit-zk/grep-color-words.tar.gz
Revert "grep: fix match highlighting for combined patterns with context lines"zk/grep-color-words
This reverts commit d5a7410d22075ecf9f2597d2516bb9914cd55049. It turns out that showing partial matches on the lines that are not matching ones is a feature, not a bug, modelling after ms/mc specifiers in GNU grep's environment variables GREP_COLORS.
-rw-r--r--grep.c42
-rwxr-xr-xt/t7810-grep.sh90
2 files changed, 20 insertions, 112 deletions
diff --git a/grep.c b/grep.c
index b363a9407b..c668034739 100644
--- a/grep.c
+++ b/grep.c
@@ -1112,33 +1112,31 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
output_sep(opt, sign);
}
if (opt->color) {
- if (sign == ':') {
- /* paint the hits on matched lines */
- regmatch_t match;
- enum grep_context ctx = GREP_CONTEXT_BODY;
- int ch = *eol;
- int eflags = 0;
+ regmatch_t match;
+ enum grep_context ctx = GREP_CONTEXT_BODY;
+ int ch = *eol;
+ int eflags = 0;
+ if (sign == ':')
line_color = opt->color_selected;
- *eol = '\0';
- while (next_match(opt, bol, eol, ctx, &match, eflags)) {
- if (match.rm_so == match.rm_eo)
- break;
-
- output_color(opt, bol, match.rm_so, line_color);
- output_color(opt, bol + match.rm_so,
- match.rm_eo - match.rm_so,
- opt->color_match);
- bol += match.rm_eo;
- rest -= match.rm_eo;
- eflags = REG_NOTBOL;
- }
- *eol = ch;
- } else if (sign == '-') {
+ else if (sign == '-')
line_color = opt->color_context;
- } else if (sign == '=') {
+ else if (sign == '=')
line_color = opt->color_function;
+ *eol = '\0';
+ while (next_match(opt, bol, eol, ctx, &match, eflags)) {
+ if (match.rm_so == match.rm_eo)
+ break;
+
+ output_color(opt, bol, match.rm_so, line_color);
+ output_color(opt, bol + match.rm_so,
+ match.rm_eo - match.rm_so,
+ opt->color_match);
+ bol += match.rm_eo;
+ rest -= match.rm_eo;
+ eflags = REG_NOTBOL;
}
+ *eol = ch;
}
output_color(opt, bol, rest, line_color);
opt->output(opt, "\n", 1);
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 87d1242548..f698001c99 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -1195,94 +1195,4 @@ test_expect_success LIBPCRE 'grep -P "^ "' '
test_cmp expected actual
'
-cat >expected <<EOF
-space-line without leading space1
-space: line <RED>with <RESET>leading space1
-space: line <RED>with <RESET>leading <RED>space2<RESET>
-space: line <RED>with <RESET>leading space3
-space:line without leading <RED>space2<RESET>
-EOF
-
-test_expect_success 'grep --color -e A -e B with context' '
- test_config color.grep.context normal &&
- test_config color.grep.filename normal &&
- test_config color.grep.function normal &&
- test_config color.grep.linenumber normal &&
- test_config color.grep.match red &&
- test_config color.grep.selected normal &&
- test_config color.grep.separator normal &&
-
- git grep --color=always -C2 -e "with " -e space2 space |
- test_decode_color >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-space-line without leading space1
-space- line with leading space1
-space: line <RED>with <RESET>leading <RED>space2<RESET>
-space- line with leading space3
-space-line without leading space2
-EOF
-
-test_expect_success 'grep --color -e A --and -e B with context' '
- test_config color.grep.context normal &&
- test_config color.grep.filename normal &&
- test_config color.grep.function normal &&
- test_config color.grep.linenumber normal &&
- test_config color.grep.match red &&
- test_config color.grep.selected normal &&
- test_config color.grep.separator normal &&
-
- git grep --color=always -C2 -e "with " --and -e space2 space |
- test_decode_color >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-space-line without leading space1
-space: line <RED>with <RESET>leading space1
-space- line with leading space2
-space: line <RED>with <RESET>leading space3
-space-line without leading space2
-EOF
-
-test_expect_success 'grep --color -e A --and --not -e B with context' '
- test_config color.grep.context normal &&
- test_config color.grep.filename normal &&
- test_config color.grep.function normal &&
- test_config color.grep.linenumber normal &&
- test_config color.grep.match red &&
- test_config color.grep.selected normal &&
- test_config color.grep.separator normal &&
-
- git grep --color=always -C2 -e "with " --and --not -e space2 space |
- test_decode_color >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-hello.c-#include <stdio.h>
-hello.c=int main(int argc, const char **argv)
-hello.c-{
-hello.c: pr<RED>int<RESET>f("<RED>Hello<RESET> world.\n");
-hello.c- return 0;
-hello.c- /* char ?? */
-hello.c-}
-EOF
-
-test_expect_success 'grep --color -e A --and -e B -p with context' '
- test_config color.grep.context normal &&
- test_config color.grep.filename normal &&
- test_config color.grep.function normal &&
- test_config color.grep.linenumber normal &&
- test_config color.grep.match red &&
- test_config color.grep.selected normal &&
- test_config color.grep.separator normal &&
-
- git grep --color=always -p -C3 -e int --and -e Hello --no-index hello.c |
- test_decode_color >actual &&
- test_cmp expected actual
-'
-
test_done