From: René Scharfe Date: Sun, 26 Oct 2014 18:15:24 GMT Subject: Re: [PATCH] grep: fix match highlighting for combined patterns with context lines Message-ID: <544D3A3C.4080906@web.de> In-Reply-To: <1413870963-66431-1-git-send-email-zoltan.klinger@gmail.com> Am 21.10.2014 um 07:56 schrieb Zoltan Klinger: > When git grep is run with combined patterns such as '-e p1 --and -e p2' > and surrounding context lines are requested, the output contains > incorrectly highlighted matches. > > Consider the following output (highlighted matches are surrounded by '*' > characters): > $ cat testfile > foo a > foo b > foo bar > baz bar foo > bar x > bar y > $ git grep -n -C2 -e foo --and -e bar testfile > testfile-1-*foo* a > testfile-2-*foo* b > testfile:3:*foo* *bar* > testfile:4:baz *bar* *foo* > testfile-5-*bar* x > testfile-6-*bar* y > > Lines 1, 2, 5 and 6 do not match the combined patterns, they only > contain incorrectly highlighted 'false positives'. The old code highlights all search terms, anywhere. I wouldn't call the ones in the context lines false positives. The user might be interested in those occurrences as well (I know I am ;). GNU grep allows coloring to be configured in much greater detail with its GREP_COLORS variable. I didn't think that level of tuning is desirable until now. What your patch does is equivalent to change the default of "ms=01;31:mc=01;31" (color matching string in selected lines and context lines) to "ms=01;31:mc=" (color matching string in selected lines). The difference is only visible with -v or git grep's --not and --and. So, if you really don't want matching string in context lines to be colored, perhaps it's time to add a color.grep.contextmatch for matching text in context lines? René