Re: Howto apply a patch/diff file
Posted: 16 Aug 2011 20:38
Check again. Or just click that link.
The place to talk about Transport Tycoon
https://www.tt-forums.net/
Code: Select all
svn update -r(Version number)
Code: Select all
patch -p0 -i name.diff
It updates your local copy of the source code to a specific version. Every time one of the developers makes a commit (=changes something to the official source) the revision number is increased by one. A source code patch is basically a file that lists a number of changes compared to some specific version. That's why you have to get that specific version first before applying a patch. Versions that are close enough might work if the official changes don't conflict with the changes made in the patch, but there is no way to guarantee that.kotssmurf wrote:Can anybody explain me exactly what this line of code does?Code: Select all
svn update -r(Version number)
-p0 tells the program patch to strip 0 leading directories from each path found in the diff. -i is just an indication that the next argument will be the filename of the diff to apply.- Second line to apply the patch to the source:I've tried the help command but can't seem to find what -p0 and -i do as attributes...Code: Select all
patch -p0 -i name.diff
You can open that file in a text editor and see for yourself, it's a shell script.- Lastly: When compiling you should change directory to source folder and execute './configure' and 'make'
I found a very small file named configure (6kb), what exactly does this point to, or execute?
Yes, but indirectly. make is a program that helps in compiling by determining which files have to be rebuild. If after compiling the first time you only change one file and execute make again, it'll only recompile that file to see you a lot of time. The actual compiling is done by a compiler, in your case gnu g++.And I assume the make command created the exe file?
A patch file contains information like "change line XXX from AAA to BBB", when there were too many changes to the code since the patch was created, it might not cleanly apply anymore, so this command makes you get an older version of the code. you might miss some new features of the past few weeks, but the patch should apply correctly.kotssmurf wrote: - To apply the patch to the source I started by using this code:Can anybody explain me exactly what this line of code does?Code: Select all
svn update -r(Version number)
"-i <name.diff>" means "input file", otherwise patch reads from the console, i.e. you have to type in everything by hand.- Second line to apply the patch to the source:I've tried the help command but can't seem to find what -p0 and -i do as attributes...Code: Select all
patch -p0 -i name.diff
Does anybody have the answer?
"configure" is a script that detects your operating system, position of some required programs, libraries, etc. and other options, and creates a file called "Makefile" taking these things into account.- Lastly: When compiling you should change directory to source folder and execute './configure' and 'make'
I found a very small file named configure (6kb), what exactly does this point to, or execute?
And I assume the make command created the exe file?
This changes the souce files to the state of that particular revision number.kotssmurf wrote:svn update -r(Version number)
If you look inside a diff/patch file, you see the paths and filenames of the files that are changed. Usually, these will be A/path/to/file.ex and B/path/to/file.ext (first for the original version, second for the changes). Because your source doesn't have a folder A or B, you need to strip this from the path. The -p option does that for you and you specify how many folders to strip from the front. -p0 doesn't strip anything; -p1 strips in this case the A/ and B/. -p2 would strip A/path/ and B/path/ etc. It is common that you need to specify -p1.kotssmurf wrote:patch -p0 -i name.diff
that was my thought as wellFooBar wrote:Darn. I was typing something nice and now Yexo beat me to it
I'm not going to throw out a perfectly good reply
yes, but the typical use case is pipes, to use the output of another programkotssmurf wrote:I could just type it in the shell?
Code: Select all
curl -L <URL> | patch -p0
that depends, if only few revisions are inbetween, then there are likely no conflicts, or they can be usually be resolved manually without a lot of effort, if you know what the patch does. a "complete rewrite" is only necessary if the patch is very old, or contradicts another patch (like "grass growth" and "stuck counter" patches are incompatible, because they use the same map bits, one of them would have to be rewritten to use other map bits, if the other one were to be included in trunk. they cannot be in the same patchpack either this way)Secondly, if the source version should allways be updated I assume that patches written to be compatible with different source codes will (in most cases) not work together? Then how are patchpacks possible? A complete manual rewrite of the code is inevitable, no?
Theoretically yes. In practice all patches are made by editing the source code and letting svn figure out what exactly changed between the version in the repository and the version on your harddisk.kotssmurf wrote:So if I were to start creating a patch and would know the nested code by heart I could just type it in the shell?
(Theoretically, I do not have the intention of ever doing this )
It's usually not that much work to update a patch to apply to a different revision. Merging multiple conflicting patches (as explained above) is more work. That requires some programming knowledge and understanding of both patches and the original code.Then how are patchpacks possible? A complete manual rewrite of the code is inevitable, no?
This i figured out already, but say we are talking about 2 patches which are compatible, but one is made with a very old source code and another is new. Can I then execute svn update -r(Very old version) and when this is done execute the same code the update to a newer source for the newer patch? Won't this overwrite the patch already executed?Yexo wrote:Correct. Even when multiple patches are written for the same version they might conflict because they change the same lines. Imagine patch 1 saying change the AA on line 3 to BB and patch 2 saying change the AA on line 3 to CC. A computer program can't solve that automatically.
You can try, but if the difference in version is quite big you'll most likely get errors when trying to update from the old version with patch applied to a newer version. These conflicts will be marked in the source code files and will have to be solved by you before compiling or applying another patch.kotssmurf wrote:This i figured out already, but say we are talking about 2 patches which are compatible, but one is made with a very old source code and another is new. Can I then execute svn update -r(Very old version) and when this is done execute the same code the update to a newer source for the newer patch? Won't this overwrite the patch already executed?!
the second "svn update" will try to keep your changes, but it may detect "conflicts" when your patch changed lines that also were changed in one of the updates.kotssmurf wrote:Aha so that means that when you perform 'SVN update -r(version number)' it does not just overwrite current source, but verifies the changes?
EDIT: nvm I replied to quick
Code: Select all
<<< mine
aaaa
======
bbbb
>>> r12345