From: René Scharfe Date: Sat, 23 May 2009 11:45:26 +0000 (+0200) Subject: grep: fix word-regexp at the beginning of lines X-Git-Tag: v1.6.3.2~6^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dbb6a4ada6c6c1065b62313127ff032196e9d232;p=git.git grep: fix word-regexp at the beginning of lines After bol is forwarded, it doesn't represent the beginning of the line any more. This means that the beginning-of-line marker (^) mustn't match, i.e. the regex flag REG_NOTBOL needs to be set. This bug was introduced by fb62eb7fab97cea880ea7fe4f341a4dfad14ab48 ("grep -w: forward to next possible position after rejected match"). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff --git a/grep.c b/grep.c index a649f063c..cc6d5b04c 100644 --- a/grep.c +++ b/grep.c @@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, bol = pmatch[0].rm_so + bol + 1; while (word_char(bol[-1]) && bol < eol) bol++; + eflags |= REG_NOTBOL; if (bol < eol) goto again; } diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index b81593780..f275af824 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -16,12 +16,13 @@ test_expect_success setup ' echo foo mmap bar_mmap echo foo_mmap bar mmap baz } >file && + echo ww w >w && echo x x xx x >x && echo y yy >y && echo zzz > z && mkdir t && echo test >t/t && - git add file x y z t/t && + git add file w x y z t/t && test_tick && git commit -m initial ' @@ -48,6 +49,12 @@ do diff expected actual ' + test_expect_success "grep -w $L (w)" ' + : >expected && + ! git grep -n -w -e "^w" >actual && + test_cmp expected actual + ' + test_expect_success "grep -w $L (x)" ' { echo ${HC}x:1:x x xx x