Page MenuHomeFreeBSD

grep: avoid duplicated lines when we're coloring output
AcceptedPublic

Authored by kevans on Wed, Mar 12, 4:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Mar 16, 9:15 AM
Unknown Object (File)
Fri, Mar 14, 12:02 PM
Unknown Object (File)
Fri, Mar 14, 12:34 AM
Unknown Object (File)
Thu, Mar 13, 9:01 PM
Unknown Object (File)
Thu, Mar 13, 8:02 PM
Unknown Object (File)
Thu, Mar 13, 10:08 AM
Unknown Object (File)
Thu, Mar 13, 10:08 AM
Unknown Object (File)
Wed, Mar 12, 4:54 AM

Details

Reviewers
emaste
des
Summary

For the default uncolored output, we'll just output a line once and then
move on. For colored output, we'll output multiple matches per
line with context from the line interspersed and may end up writing out
some match context multiple times as we don't persist which part of the
lines have already been printed.

Fix it by tracking the length of line printed thus far in printline()
and retaining it across successive calls to printline() in the same
line. printline() should indicate whether it terminated the line or not
to avoid tracking the logic for that in multiple places: -o lines are
always terminated, so it's generally only some --color contexts where we
wouldn't have terminated.

Add a test to make sure that we're only printing one line going forward.

Reported by: Jamie Landeg-Jones <jamie catflap org>

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 62880
Build 59764: arc lint + arc unit

Event Timeline

Looks reasonable

usr.bin/grep/tests/grep_freebsd_test.sh
116

Doesn't matter of course, but . doesn't need quoting

This revision is now accepted and ready to land.Wed, Mar 12, 12:03 PM

Works perfectly for me on a recent 14-stable.

Thanks!