summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a9b2d42)
raw | patch | inline | side by side (parent: a9b2d42)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Wed, 3 Jun 2009 16:19:01 +0000 (18:19 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 3 Jun 2009 18:32:29 +0000 (11:32 -0700) |
The command "git grep -w ''" dies as soon as it encounters an empty line,
reporting (wrongly) that "regexp returned nonsense". The first hunk of
this patch relaxes the sanity check that is responsible for that,
allowing matches to start at the end.
The second hunk complements it by making sure that empty matches are
rejected if -w was specified, as they are not really words.
GNU grep does the same:
$ echo foo | grep -c ''
1
$ echo foo | grep -c -w ''
0
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reporting (wrongly) that "regexp returned nonsense". The first hunk of
this patch relaxes the sanity check that is responsible for that,
allowing matches to start at the end.
The second hunk complements it by making sure that empty matches are
rejected if -w was specified, as they are not really words.
GNU grep does the same:
$ echo foo | grep -c ''
1
$ echo foo | grep -c -w ''
0
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c | patch | blob | history |
index 7bf4a60ac7704e16abe9054296c1e0e77c984344..92a47c71e7d93eef7dc8d6967cd071aa061218ce 100644 (file)
--- a/grep.c
+++ b/grep.c
if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
- (eol - bol) <= pmatch[0].rm_so ||
+ (eol - bol) < pmatch[0].rm_so ||
(pmatch[0].rm_eo < 0) ||
(eol - bol) < pmatch[0].rm_eo)
die("regexp returned nonsense");
else
hit = 0;
+ /* Words consist of at least one character. */
+ if (pmatch->rm_so == pmatch->rm_eo)
+ hit = 0;
+
if (!hit && pmatch[0].rm_so + bol + 1 < eol) {
/* There could be more than one match on the
* line, and the first match might not be