提交 34894283 编写于 作者: J Junio C Hamano

Merge branch 'rs/maint-grep-word-regexp-fix' into maint

* rs/maint-grep-word-regexp-fix:
  grep: fix colouring of matches with zero length
  grep: fix word-regexp at the beginning of lines
...@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, ...@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
bol = pmatch[0].rm_so + bol + 1; bol = pmatch[0].rm_so + bol + 1;
while (word_char(bol[-1]) && bol < eol) while (word_char(bol[-1]) && bol < eol)
bol++; bol++;
eflags |= REG_NOTBOL;
if (bol < eol) if (bol < eol)
goto again; goto again;
} }
...@@ -499,6 +500,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, ...@@ -499,6 +500,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
*eol = '\0'; *eol = '\0';
while (next_match(opt, bol, eol, ctx, &match, eflags)) { while (next_match(opt, bol, eol, ctx, &match, eflags)) {
if (match.rm_so == match.rm_eo)
break;
printf("%.*s%s%.*s%s", printf("%.*s%s%.*s%s",
(int)match.rm_so, bol, (int)match.rm_so, bol,
opt->color_match, opt->color_match,
......
...@@ -16,12 +16,13 @@ test_expect_success setup ' ...@@ -16,12 +16,13 @@ test_expect_success setup '
echo foo mmap bar_mmap echo foo mmap bar_mmap
echo foo_mmap bar mmap baz echo foo_mmap bar mmap baz
} >file && } >file &&
echo ww w >w &&
echo x x xx x >x && echo x x xx x >x &&
echo y yy >y && echo y yy >y &&
echo zzz > z && echo zzz > z &&
mkdir t && mkdir t &&
echo test >t/t && echo test >t/t &&
git add file x y z t/t && git add file w x y z t/t &&
test_tick && test_tick &&
git commit -m initial git commit -m initial
' '
...@@ -48,6 +49,12 @@ do ...@@ -48,6 +49,12 @@ do
diff expected actual 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)" ' test_expect_success "grep -w $L (x)" '
{ {
echo ${HC}x:1:x x xx x echo ${HC}x:1:x x xx x
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册