473,507 Members | 5,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restore a unified diff

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 <al***@cse.ohio-state.edu>
Jul 18 '05 #1
3 4190
[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.
Jul 18 '05 #2
Tim Peters <ti********@gmail.com> 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 <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #3
[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.
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1757
by: Eric J. Holtman | last post by:
Of course I'll try this before I go live, but I figured I'd ask here first. I've read the docs, and the answer is unclear. My current backup strategy is: Take a full database backup...
9
6501
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
2062
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
6
6433
by: Igor Shevchenko | last post by:
Hi! Suppose I have "pg_dump -s" of two pg installs, one is "dev", another is "production". Their schemas don't differ too much, and I want to get a "diff -u"-like schema diff so I can quickly...
4
4934
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
2
3301
by: Asphalt Blazer | last post by:
I am running DB2 UDB v8.1 FP 14 on AIX 5.3 I have two servers ServerA and ServerB. ServerA has instance InstA ServerB has instance InstB InstA has database DB1. DB1 is being backed up daily...
1
3126
by: erikcw | last post by:
Hi, I'm trying to create an undo/redo feature for a webapp I'm working on (django based). I'd like to have an undo/redo function. My first thought was to use the difflib to generate a diff to...
6
3280
by: Aaron Gray | last post by:
Hi, I am working on an HTML WYSISYG Wiki and need to display a diff page like WikiPedia does if two people edit a file at the same time to give the second user the diff. Basically with additions...
1
1433
harshadd
by: harshadd | last post by:
http://images.orkut.com/orkut/photos/OgAAAPCx9BDT2K9eZgmdGn5dAG_oKl7hf_SnAM8q4fIPozZ1oOIYdzAwHLfBA1HFlX6F04O5kWMQGYlUiHs7NbwPm10Am1T1UJ6Eoc0OhIb-Tkbf1rcJlIni46gd.jpg Pls see the above error I am...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.