Merge branch 'rs/grep-column-only-match-fix' into next

"git grep" update.

* rs/grep-column-only-match-fix:
  grep: fix --column --only-match for 2nd and later matches
Junio C Hamano 2026-05-11 13:57:44 +09:00
commit a0d87e3104
2 changed files with 5 additions and 4 deletions

3
grep.c
View File

@ -1267,6 +1267,7 @@ static void show_line(struct grep_opt *opt,
regmatch_t match;
enum grep_context ctx = GREP_CONTEXT_BODY;
int eflags = 0;
const char *start = bol;

if (want_color(opt->color)) {
if (sign == ':')
@ -1285,6 +1286,7 @@ static void show_line(struct grep_opt *opt,
if (match.rm_so == match.rm_eo)
break;

cno = bol - start + match.rm_so + 1;
if (opt->only_matching)
show_line_header(opt, name, lno, cno, sign);
else
@ -1294,7 +1296,6 @@ static void show_line(struct grep_opt *opt,
if (opt->only_matching)
opt->output(opt, "\n", 1);
bol += match.rm_eo;
cno += match.rm_eo;
rest -= match.rm_eo;
eflags = REG_NOTBOL;
}

View File

@ -322,11 +322,11 @@ do
${HC}file:1:5:mmap
${HC}file:2:5:mmap
${HC}file:3:5:mmap
${HC}file:3:13:mmap
${HC}file:3:14:mmap
${HC}file:4:5:mmap
${HC}file:4:13:mmap
${HC}file:4:14:mmap
${HC}file:5:5:mmap
${HC}file:5:13:mmap
${HC}file:5:14:mmap
EOF
git grep --column -n -o -e mmap $H >actual &&
test_cmp expected actual