Gigigonzalez wrote:Hi all. Im trying to patch older/newer revision patches versus a trunk version, and Its going fairly well. I kind of use notepad ++ (side by side) to compare and try to find the exact spot on where the new lines should be, or which ones should be removed.
Is there some easier way to do this? Or am i doing it right? Is this the proper way to do it?
No, probably not, mostly.
Assuming those answers made little sense, a somewhat longer answer
A source file is "a work under construction". A revision is a point in time for the work. A patch is a proposed change for the work under construction, at a given revision.
It is pretty likely that the patch will work for the given revision.
When you change the revision, the work under construction changes. 'Physically', lines of text get added, moved, changed, or even removed. The more important changes are the semantical changes. These are however not always visible in the file that you change. The set of allowed values in a variable gets smaller or bigger. Enumerations get additional values. New variables are added that have to be taken into account as well. Variables change meaning, or its unit changes.
To make it more concrete, a somewhat contrived example
Code: Select all
int f(int x, y) {
y = x + y;
+ y /= x;
return y;
}
The patch line (indicated with "+") scales y w.r.t x. In one revision this works. Say that in the next revision, variable 'x' is extended with the value "0", meaning "x is not relevant". In the unpatched version, nothing has to change, y+x == y when x == 0, which nicely matches "x does not play".
However if you add the patch line in the new revision, you will cause a crash of the program.
So conceptually, to apply a line with a change, you have to check that the change will work under every condition in the current revision, in particular taking all changes since the patch was created, into account.
This is pretty close to actually programming the patch again.
Your approach of just finding the point to insert the changed line will thus fail in the general case, if you don't take care of the semantical changes that happen with each change.
However, if you look at the changes made from revision to revision, and they do not touch the area of your patch (say your patch is about towns, and the revisions do stuff in cargo packets), it is fairly safe to assume the patch will still work. (Often it will even apply cleanly in such a case.)
There is thus no easier way, in fact the really proper way is like normal programming the patch again.
Your approach is more risky, but may work in a lot of cases.