{"thread":{"id":"19424","subject":"git-grep colouring bug with -w option.","startedAt":"2009-05-20T18:38:57Z","lastAt":"2009-05-21T04:29:03Z","messageCount":3,"participants":["Dmitry Gryazin","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114366","messageId":"4A144E41.4010303@gmail.com","threadId":"19424","inReplyTo":null,"subject":"git-grep colouring bug with -w option.","fromName":"Dmitry Gryazin","fromEmail":"dosagc@gmail.com","sentAt":"2009-05-20T18:38:57Z","receivedAt":"2009-05-20T18:38:57Z","isPatch":false,"sender":{"key":"dosagc@gmail.com","avatar":null},"body":"I've found that \"git-grep --color -w VirtualKeybord\" works not correct \nfor string like:\n\nvkbd = RVirtualKeyboard(main_window, \"VirtualKeyboard\")\n\nMy script in attachment reproduces this bug.\n"},{"id":"114370","messageId":"4A1476C9.8060900@lsrfire.ath.cx","threadId":"19424","inReplyTo":"4A144E41.4010303@gmail.com","subject":"[PATCH] grep: fix word-regexp colouring","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-05-20T21:31:53Z","receivedAt":"2009-05-20T21:31:53Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"As noticed by Dmitry Gryazin: When a pattern is found but it doesn't\nstart and end at word boundaries, bol is forwarded to after the match and\nthe pattern is searched again.  When a pattern is finally found between\nword boundaries, the match offsets are off by the number of characters\nthat have been skipped.\n\nThis patch corrects the offsets to be relative to the value of bol as\npassed to match_one_pattern() by its caller.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n grep.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 04c777a..a649f06 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,\n {\n \tint hit = 0;\n \tint saved_ch = 0;\n+\tconst char *start = bol;\n \n \tif ((p->token != GREP_PATTERN) &&\n \t    ((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))\n@@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,\n \t}\n \tif (p->token == GREP_PATTERN_HEAD && saved_ch)\n \t\t*eol = saved_ch;\n+\tif (hit) {\n+\t\tpmatch[0].rm_so += bol - start;\n+\t\tpmatch[0].rm_eo += bol - start;\n+\t}\n \treturn hit;\n }\n \n-- \n1.6.3.1\n"},{"id":"114391","messageId":"4A14D88F.8010105@gmail.com","threadId":"19424","inReplyTo":"4A1476C9.8060900@lsrfire.ath.cx","subject":"Re: [PATCH] grep: fix word-regexp colouring","fromName":"Dmitry Gryazin","fromEmail":"dosagc@gmail.com","sentAt":"2009-05-21T04:29:03Z","receivedAt":"2009-05-21T04:29:03Z","isPatch":true,"sender":{"key":"dosagc@gmail.com","avatar":null},"body":"René Scharfe wrote:\n> As noticed by Dmitry Gryazin: When a pattern is found but it doesn't\n> start and end at word boundaries, bol is forwarded to after the match and\n> the pattern is searched again.  When a pattern is finally found between\n> word boundaries, the match offsets are off by the number of characters\n> that have been skipped.\n>\n> This patch corrects the offsets to be relative to the value of bol as\n> passed to match_one_pattern() by its caller.\n>\n> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n> ---\n>  grep.c |    5 +++++\n>  1 files changed, 5 insertions(+), 0 deletions(-)\n>\n> diff --git a/grep.c b/grep.c\n> index 04c777a..a649f06 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -305,6 +305,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,\n>  {\n>  \tint hit = 0;\n>  \tint saved_ch = 0;\n> +\tconst char *start = bol;\n>  \n>  \tif ((p->token != GREP_PATTERN) &&\n>  \t    ((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))\n> @@ -365,6 +366,10 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,\n>  \t}\n>  \tif (p->token == GREP_PATTERN_HEAD && saved_ch)\n>  \t\t*eol = saved_ch;\n> +\tif (hit) {\n> +\t\tpmatch[0].rm_so += bol - start;\n> +\t\tpmatch[0].rm_eo += bol - start;\n> +\t}\n>  \treturn hit;\n>  }\n>  \n>   \nThanks.\n\nACK\n"}]}