Page MenuHomeFreeBSD

diff: fix side-by-side output with tabbed input
ClosedPublic

Authored by kevans on Dec 12 2022, 5:29 AM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 20 2023, 7:58 AM
Unknown Object (File)
Dec 20 2023, 7:58 AM
Unknown Object (File)
Dec 12 2023, 3:12 AM
Unknown Object (File)
Nov 27 2023, 2:04 PM
Unknown Object (File)
Jul 10 2023, 7:18 PM
Unknown Object (File)
Jun 19 2023, 8:05 PM
Unknown Object (File)
Jun 19 2023, 1:41 PM
Unknown Object (File)
May 13 2023, 4:04 AM
Subscribers

Details

Summary

The previous logic conflated some things... in this block:

  • j: input characters rendered so far
  • nc: number of characters in the line
  • col: columns rendered so far
  • hw: column width ((h)ard (w)idth?)

Comparing j to hw or col to nc are naturally wrong, as col and hw are
limits on their respective counters and nc is already brought down to hw
if the input line should be truncated to start with.

Right now, we end up easily truncating lines with tabs in them as we
count each tab for $tabwidth lines in the input line, but we really
should only be accounting for them in the column count. The problem is
mostly easily demonstrated by the two input files added for the tests,
the two tabbed lines lose at least a word or two even though there's
plenty of space left in the row for each side.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Dec 12 2022, 8:02 AM
pstef added a subscriber: pstef.

hw: column width ((h)ard (w)idth?)

My completely baseless guess is that the h might stand for horizontal.

usr.bin/diff/diffreg.c
1250–1251

style suggestion: we could move the initialization to before this loop, move the step part to the end of the loop (there are no continues or breaks) and keep the condition within a while ()

1279

I don't feel strongly about printf performance in diff, but calling printf within a loop doesn't look great. Of course I understand this code isn't new so may be out of the scope of this patch. Just can't not see it.

usr.bin/diff/diffreg.c
1250–1251

That feels like possible bikeshed bait, so I've queued it up as a second commit in case someone complains about it.

1279

Yeah, I'm going to punt on this one -- most of the time we're talking <= 8 iterations at a time, and this is a non-default path.