fmt: default the width to goal + 10 when only --goal is given - #14275
fmt: default the width to goal + 10 when only --goal is given#14275abhijeetvichare76 wants to merge 1 commit into
Conversation
7a13b67 to
8cd2371
Compare
|
Binary size comparison: |
|
GNU testsuite comparison: |
4f93667 to
ab800ea
Compare
luantaraschi
left a comment
There was a problem hiding this comment.
I went and pinned GNU's actual rule here, because it is an easy one to get backwards, and this has it right.
GNU validates the goal against the default width first and widens afterwards, so the ceiling is 75 rather than the widened value:
$ fmt -g 75 f ok
$ fmt -g 76 f fmt: invalid width: '76': Numerical result out of range
which is why keeping the g > DEFAULT_WIDTH check next to the new w = g + DEFAULT_GOAL_WIDTH_SLACK is correct and not a leftover. Somebody reading the diff cold could easily take it for one. I compared -g G on its own against -w G+10 -g G on GNU coreutils 8.32 across the range and they agree.
One optional note on the test. Asserting that a 37 column paragraph fits at goal 30 pins the outcome but not the rule, so a wrong goal + 20 would pass it too. Comparing -g G against -w G+10 -g G would pin the rule itself.
GNU documents the width as "75, or goal + 10 if goal is provided", and `fmt -g N` is byte-identical to `fmt -w N+10 -g N` there. We instead inverted the 93% rule, which gives a narrower width and so breaks lines GNU keeps together: with -g 30 the width came out as 33 rather than 40. This is only part of the difference reported in uutils#5162; the line-breaking cost function still disagrees with GNU once the width matches.
ab800ea to
5690d62
Compare
|
Hi @luantaraschi thanks for reviewing! Also, dropped the old |
|
That pins the rule rather than the outcome. Thanks. |
GNU documents the width as "75, or goal + 10 if goal is provided", and
fmt -g Nis byte-identical tofmt -w N+10 -g Nthere. We derived the width by inverting the 93% goal ratio instead, which comes out narrower and breaks lines GNU keeps together:With
-g 30our width was 33 rather than 40, so the 37-column paragraph did not fit.Refs #5162. That issue also covers a second difference which this does not address: once the width matches, the line-breaking cost function still disagrees with GNU, because it penalises a line for overshooting the goal as heavily as for undershooting it. The two
#[ignore]d tests intest_fmt.rsneed that part too, so they stay ignored here.