forked from msysgit/git
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grep: fix match highlighting for combined patterns with context lines
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'. Modify the show_line() function in grep.c to highlight matches only on lines that match the combined pattern. Do not highlight matches on lines that provide only context or contain only the function name of the match. The output of the same command after the change: $ 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 Also avoid unnecessary regmatch on lines we do not split by moving the code to paint a single line piece-by-piece only to apply to the matched line. Signed-off-by: Zoltan Klinger <zoltan.klinger@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Showing
2 changed files
with
112 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters