[Toybox] New diff.c

Rob Landley rob at landley.net
Sun Aug 14 21:29:51 PDT 2022


On 8/14/22 18:20, Ray Gardner wrote:
> [I tried sending this to the toybox list but don't see it there. I
> also tried subscribing but that doesn't seem to have worked.]
> 
> Rob, I don't know if you've done much work on diff.c since your Aug. 8
> post that had attachment.c, but I tried that program and it apparently
> gets into an infinite loop with a certain pair of files. I can send
> them to you or attach them to a post here if you like.

I fixed a couple bugs since then, but I'm always happy to have more test cases.

I checked it into a branch like Elliott suggested, and have done all my commits
since to that branch too. (Use the TOYFLAG_ARGFAIL() value for error_msg(),
added sort -C, fixed the block device drivers for m68k and powerpc in the mkroot
builds...)

But can't push it to github until I'm ready for that diff.c to be load bearing,
since the commit replaced the old one. Working on it...

> [The following was not in the post to the list:]
> 
> In a list post August 8 you wrote:
>> this means with -U 3 you can have up to 5 consecutive matching lines in the middle of a hunk
> 
> Actually you can have up to 6 consecutive matching lines in a hunk.
> The spec says "If -U n is specified, the output shall contain no more
> than 2 n consecutive unaffected lines" and gnu diff agrees.

Was this an errata? My downloaded copy says:

> If -U n is specified, the output shall contain no more than n consecutive
> unaffected lines; and if the output contains an affected line and this line is
> adjacent to up to n consecutive unaffected lines in the corresponding file,
> the output shall contain these unaffected lines. -u shall act like -U3.

Ah, it has changed since 2008 and 2018:

https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/diff.html
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/diff.html

I hadn't actually tested the boundary condition, I was just focused on what
would make an illegal hunk. But I should add a test case for this and fix up the
code. (Sigh, and this says that ending a hunk is 2N+1 consecutive lines.

(Sigh. Following this logic, since the new hunk needs +++ --- and @@@ lines it
would be 2N+3 consecutive lines as the breakeven point. But anything less than 5
produces a hunk that CAN'T be applied because you'd have to rewind the output.)

> Ray Gardner
> Centennial, CO
> raygard.net, github.com/raygard
I see your message in the moderation queue, I can fix it up when I get home.
(Dreamhost is biologically incapable of applying the landley.net https
certificate to the lists server, so I'm not comfortable doing moderation on wifi.)

I'm guessing you're subscribed now, but subscribing doesn't affect the messages
already held for moderator approval.

Thanks,

Rob


More information about the Toybox mailing list