diff -u, -e

Rob Landley rob at landley.net
Sat Jun 27 02:19:09 UTC 2009


On Friday 26 June 2009 15:30:39 Cathey, Jim wrote:
> >Unified diff format is ubiquitous.  I can see the point of adding a NOP
>
> -u
>
> >option just so busybox diff won't complain about scripts that specify
>
> that,
>
> It already quietly accepts -u.
> Are -u's sed-able to non-u's?

I expect so.  The ancient ed-based default format had significantly _less_ 
information, and a lossy conversion is usally pretty easy to do.

Let's see, the obsolete format doesn't ever name the files being modified, so 
the -u format's +++ and --- lines can be dropped entirely.  Similarly use 
can't use context lines with the ed option or it shoehorns you into a unified-
like format with + and - instead of > and <, so _those_ can be dropped too.

Converting the + and - lines to > and < is fairly trivial.  Converting the 8 
different types of ed subcommands identifying line position is slightly more of 
a bother, primarily because the darn standard doesn't say what the four 
numbers MEAN:

  http://www.opengroup.org/onlinepubs/9699919799/utilities/diff.html

And instead assumes you know ed syntax.  But in theory you could just convert 
every -u header into the ed four number format every time.

But then I really don't know what input format your script is expecting.  The 
ed-based default is one format (with -f and -e variants), the one you get with 
-C3 is another format entirely (similar to -u but with more complicated 
headers and using ! for changed lines).  I don't know if your scripts _depend_ 
on getting all eight variants ("1a2", "1a2,3", "1d2", "1,2d3", "1c2", "1,2c3", 
"1c2,3", and "1,2c3,4") instead of just that last one.  But then it's been 
about 12 years since I last used "ed" on the sun workstations at rutgers, and 
I don't remember anything about its command syntax other than the way it 
explained the existence of dos edlin.

> We have products where we are _using_
> 'obsolete' diff formats, and now we're
> starting to use BB to build some of them.

And naturally you wouldn't change the code that's using the obsolete formats 
when migrating to a new environment.

> Currently the diffy features are un-implementable.
>
> You have an alternative suggestion?

Several.

(I suppose this is my fault for applying the ed patch back in 2006 rather than 
just deleting it.  I shoulda said no...)

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds


More information about the busybox mailing list