Skip to content

Commit 3489428

Browse files
committed
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
2 parents b91ffd3 + 1f5b9cc commit 3489428

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

grep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
360360
bol = pmatch[0].rm_so + bol + 1;
361361
while (word_char(bol[-1]) && bol < eol)
362362
bol++;
363+
eflags |= REG_NOTBOL;
363364
if (bol < eol)
364365
goto again;
365366
}
@@ -499,6 +500,8 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
499500

500501
*eol = '\0';
501502
while (next_match(opt, bol, eol, ctx, &match, eflags)) {
503+
if (match.rm_so == match.rm_eo)
504+
break;
502505
printf("%.*s%s%.*s%s",
503506
(int)match.rm_so, bol,
504507
opt->color_match,

t/t7002-grep.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ test_expect_success setup '
1616
echo foo mmap bar_mmap
1717
echo foo_mmap bar mmap baz
1818
} >file &&
19+
echo ww w >w &&
1920
echo x x xx x >x &&
2021
echo y yy >y &&
2122
echo zzz > z &&
2223
mkdir t &&
2324
echo test >t/t &&
24-
git add file x y z t/t &&
25+
git add file w x y z t/t &&
2526
test_tick &&
2627
git commit -m initial
2728
'
@@ -48,6 +49,12 @@ do
4849
diff expected actual
4950
'
5051

52+
test_expect_success "grep -w $L (w)" '
53+
: >expected &&
54+
! git grep -n -w -e "^w" >actual &&
55+
test_cmp expected actual
56+
'
57+
5158
test_expect_success "grep -w $L (x)" '
5259
{
5360
echo ${HC}x:1:x x xx x

0 commit comments

Comments
 (0)