summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2009-05-20 21:31:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-05-21 01:49:20 (GMT)
commite701fadb9e0e51a6811690d95a53bd1f5b6fad86 (patch)
tree3d4c63375750ebf07fdbdfa95439a1f94a93c596 /grep.c
parent8dfb17e1fd7dec1d3a1978eb46743964c481cd08 (diff)
downloadgit-e701fadb9e0e51a6811690d95a53bd1f5b6fad86.zip
git-e701fadb9e0e51a6811690d95a53bd1f5b6fad86.tar.gz
git-e701fadb9e0e51a6811690d95a53bd1f5b6fad86.tar.bz2
grep: fix word-regexp colouring
As noticed by Dmitry Gryazin: When a pattern is found but it doesn't start and end at word boundaries, bol is forwarded to after the match and the pattern is searched again. When a pattern is finally found between word boundaries, the match offsets are off by the number of characters that have been skipped. This patch corrects the offsets to be relative to the value of bol as passed to match_one_pattern() by its caller. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/grep.c b/grep.c
index 04c777a..a649f06 100644
--- a/grep.c
+++ b/grep.c
@@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
{
int hit = 0;
int saved_ch = 0;
+ const char *start = bol;
if ((p->token != GREP_PATTERN) &&
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
@@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
}
if (p->token == GREP_PATTERN_HEAD && saved_ch)
*eol = saved_ch;
+ if (hit) {
+ pmatch[0].rm_so += bol - start;
+ pmatch[0].rm_eo += bol - start;
+ }
return hit;
}