Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Restore a unified diff

Reply
Thread Tools

Restore a unified diff

 
 
Nick Allen
Guest
Posts: n/a
 
      01-04-2005
After using ndiff from difflib, the function restore
would return the sequence that generated the delta. Unfortunately,
restore does not do the same for unified_diff. I do not see any similar
function that is intended for unified_diff. Does anyone know how to
"restore" from a unified diff generated delta?

Thanks for all your help in advance.

Best Regards,
Nick


Nick Allen <(E-Mail Removed)-state.edu>
 
Reply With Quote
 
 
 
 
Tim Peters
Guest
Posts: n/a
 
      01-05-2005
[Nick Allen]
> After using ndiff from difflib, the function restore
> would return the sequence that generated the delta.


It can actually reproduce either sequence from which the delta was
generated. But this is really trivial: ndiff was intended to produce
diff output for humans to read, and includes the full text of both
input sequences in "the diff" it generates.

> Unfortunately, restore does not do the same for unified_diff. I do
> not see any similar function that is intended for unified_diff. Does
> anyone know how to "restore" from a unified diff generated delta?


That's in general impossible, since unified diffs generally omit most
lines that compared equal to begin with. Unified and context diffs
are, in part, compression gimmicks, showing only what changed plus a
bit of context. ndiff shows everything, so can restore everything
too.
 
Reply With Quote
 
 
 
 
Mike Meyer
Guest
Posts: n/a
 
      01-05-2005
Tim Peters <(E-Mail Removed)> writes:

> [Nick Allen]
>> Unfortunately, restore does not do the same for unified_diff. I do
>> not see any similar function that is intended for unified_diff. Does
>> anyone know how to "restore" from a unified diff generated delta?

>
> That's in general impossible, since unified diffs generally omit most
> lines that compared equal to begin with. Unified and context diffs
> are, in part, compression gimmicks, showing only what changed plus a
> bit of context. ndiff shows everything, so can restore everything
> too.


The unix patch utility seems to do a fine job of handling the unix
unified and context diffs. Unified is the preferred format for the
open source projects I contribute patches to.

Possibly this is some other form of "unified diff" than what you get
from "diff -u" on a Unix system?

<mike
--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
Tim Peters
Guest
Posts: n/a
 
      01-05-2005
[Nick Allen]
>>> Unfortunately, restore does not do the same for unified_diff. I do
>>> not see any similar function that is intended for unified_diff.
>>> Does anyone know how to "restore" from a unified diff generated
>>> delta?


[Tim Peters]
>> That's in general impossible, since unified diffs generally omit
>> most lines that compared equal to begin with. Unified and
>> context diffs are, in part, compression gimmicks, showing only
>> what changed plus a bit of context. ndiff shows everything, so
>> can restore everything too.


[Mike Meyer]
> The unix patch utility seems to do a fine job of handling the unix
> unified and context diffs.


Of course it does, but "the diff" isn't the only input to `patch`, you
also need to give `patch` the original source file (or one closely
related to it). `patch` would be deep magic indeed if it could deduce
either the "before" or "after" file from a context or unified diff
*alone*. But both the "before" and "after" files *can* be deduced
from an ndiff diff alone.

This remains a truly trivial observation: ndiff can do this because
the full text of both input files is part of the output it produces.
unified/context diffs cannot generally do this because they don't
generally contain the full text of either input file.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Diff CSS styles for diff INPUT TYPE='s? A Traveler ASP .Net 6 08-31-2004 09:17 PM
[ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4 Austin Ziegler Ruby 3 08-09-2004 06:34 AM
diff Process under diff users Cyril Vi?ville Perl 1 06-29-2004 06:22 PM
Same sessionID retuned to diff browsers in diff machines Berrucho ASP .Net 2 12-05-2003 02:23 PM
Re: System Restore won't restore WinXP Pro NEMISIES Computer Support 0 06-27-2003 12:22 AM



Advertisments