Difference between revisions of "HowTo:Apply Patch"
m |
(svn v.1.7 makes it easy) |
||
Line 1: | Line 1: | ||
---- | ---- | ||
− | == | + | == Basics == |
A '''patch file''' (or '''diff file''' - it's one and the same) contains instructions on modifying a set of existing text files from known originals. It's used in Sourceforge projects to publish the newest code changes that didn't yet make it into "official" SVN, so if you want to beta-test and review [https://sourceforge.net/p/vegastrike/patches/ the lattest proposal for VS code], you need to download and apply patches. | A '''patch file''' (or '''diff file''' - it's one and the same) contains instructions on modifying a set of existing text files from known originals. It's used in Sourceforge projects to publish the newest code changes that didn't yet make it into "official" SVN, so if you want to beta-test and review [https://sourceforge.net/p/vegastrike/patches/ the lattest proposal for VS code], you need to download and apply patches. | ||
It's a very good idea to look into the patch file before applying it (they are plain text, after all). For one, it's a non-reviewed piece of code that will be executable, and you probably would like to make sure it's no more hacky than it's supposed to be. Even if you trust the source, at very least look whether it's really a patchfile and whether you're about to apply it in the same place where it expects the files to be. | It's a very good idea to look into the patch file before applying it (they are plain text, after all). For one, it's a non-reviewed piece of code that will be executable, and you probably would like to make sure it's no more hacky than it's supposed to be. Even if you trust the source, at very least look whether it's really a patchfile and whether you're about to apply it in the same place where it expects the files to be. | ||
− | == | + | == Apply patch file == |
+ | Subversion 1.7 [http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.patch.html can apply patch on its own]] with a single command, e.g.: | ||
+ | <code><br/>~/repositories/VegaStrike/trunk/vegastrike$ svn patch ~/tmp/MyLatestVSPatch.patch<br/> | ||
+ | </code> | ||
+ | Earlier versions of Subversion don't have patch subcommand, so you need other tools. | ||
− | === | + | === Linux === |
− | In Linux, you probably already have (if you got Subversion package installed on Debian/*Ubuntu, it should be there too) <code>patch</code> utility, so all you need is to | + | In Linux, you probably already have (if you got Subversion package installed on Debian/*Ubuntu, it should be there too) <code>patch</code> utility, so all you need is to go at the proper base path (relatively to which path of each file is given, the same where diff was taken - usually '''[http://sourceforge.net/p/vegastrike/code/HEAD/tree/trunk/vegastrike/ trunk/vegastrike]''') - and type in command shell: |
<code><br/> /your/working/copy/directory.../trunk/vegastrike$ patch -p0 -i /wherever/you/saved/that/patch.../PatchFileName.patch <br/> | <code><br/> /your/working/copy/directory.../trunk/vegastrike$ patch -p0 -i /wherever/you/saved/that/patch.../PatchFileName.patch <br/> | ||
</code> - e.g. | </code> - e.g. | ||
Line 22: | Line 26: | ||
If you use a Subversion front-end, it may be able to apply patch on its own, or at least open the command shell at the right place (e.g. in PySVN Workbench, right-click on the repository tree on the right panel). | If you use a Subversion front-end, it may be able to apply patch on its own, or at least open the command shell at the right place (e.g. in PySVN Workbench, right-click on the repository tree on the right panel). | ||
− | === Create patch file | + | === Windows === |
− | To create patchfiles, you need | + | There probably aren't any pre-installed utilities, but third-party ones are available (e.g. GnuWin32 [http://gnuwin32.sourceforge.net/packages/patch.htm includes it]). Also, in Windows you probably would use Subversion via front-end, and advanced ones (e.g. [http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-patch.html TortoiseSVN]) can create and apply patches all on their own. |
+ | |||
+ | == Create patch file == | ||
+ | To create patchfiles, you need only Subversion client itself. The proper command looks like this: | ||
<code><br/>~/repositories/VegaStrike/trunk/vegastrike$ svn diff src/cmd/ai src/cmd/unit.cpp >~/tmp/MyLatestVSPatch.patch <br/> | <code><br/>~/repositories/VegaStrike/trunk/vegastrike$ svn diff src/cmd/ai src/cmd/unit.cpp >~/tmp/MyLatestVSPatch.patch <br/> | ||
− | </code> - When SVN command is used | + | </code> - When SVN command is used without extra options like above, it compares the working copy with its backup base. Note that diff (standalone or SVN) will see path relatively to the place where it's running, so it's better to launch it from trunk/vegastrike too, but narrow the scope as needed via parameters - in the example src/cmd/unit.cpp and all files in src/cmd/* are checked for differences, but nothing else. |
− | == | + | == Revert patch == |
− | + | It's easy to [http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.revert.html revert] a SVN working copy or its part to the original state, but it's also possible to ''un''-apply patches one by one - at least, if the patched files aren't changed after the patch in question was applied: | |
+ | <code><br/> ~/repositories/VegaStrike/trunk/vegastrike$ patch -p0 -R -i ~/tmp/MyLatestVSPatch.patch <br/> | ||
+ | </code> or | ||
+ | <code><br/>~/repositories/VegaStrike/trunk/vegastrike$ svn patch --reverse-diff ~/tmp/MyLatestVSPatch.patch<br/> | ||
+ | </code> | ||
---- | ---- | ||
[[Category:HowTos|Apply Patch]] | [[Category:HowTos|Apply Patch]] |
Revision as of 20:55, 16 July 2013
Basics
A patch file (or diff file - it's one and the same) contains instructions on modifying a set of existing text files from known originals. It's used in Sourceforge projects to publish the newest code changes that didn't yet make it into "official" SVN, so if you want to beta-test and review the lattest proposal for VS code, you need to download and apply patches. It's a very good idea to look into the patch file before applying it (they are plain text, after all). For one, it's a non-reviewed piece of code that will be executable, and you probably would like to make sure it's no more hacky than it's supposed to be. Even if you trust the source, at very least look whether it's really a patchfile and whether you're about to apply it in the same place where it expects the files to be.
Apply patch file
Subversion 1.7 can apply patch on its own] with a single command, e.g.:
Earlier versions of Subversion don't have patch subcommand, so you need other tools.
~/repositories/VegaStrike/trunk/vegastrike$ svn patch ~/tmp/MyLatestVSPatch.patch
Linux
In Linux, you probably already have (if you got Subversion package installed on Debian/*Ubuntu, it should be there too) patch
utility, so all you need is to go at the proper base path (relatively to which path of each file is given, the same where diff was taken - usually trunk/vegastrike) - and type in command shell:
- e.g.
/your/working/copy/directory.../trunk/vegastrike$ patch -p0 -i /wherever/you/saved/that/patch.../PatchFileName.patch
If everything worked, you'll get a report like
~/repositories/VegaStrike/trunk/vegastrike$ patch -p0 -i ~/tmp/MyLatestVSPatch.patch
note that pathes here are relative to trunk/vegastrike.
patching file src/cmd/unit_generic.h
patching file src/cmd/unit.cpp
patching file src/cmd/unit_generic.cpp
If you use a Subversion front-end, it may be able to apply patch on its own, or at least open the command shell at the right place (e.g. in PySVN Workbench, right-click on the repository tree on the right panel).
Windows
There probably aren't any pre-installed utilities, but third-party ones are available (e.g. GnuWin32 includes it). Also, in Windows you probably would use Subversion via front-end, and advanced ones (e.g. TortoiseSVN) can create and apply patches all on their own.
Create patch file
To create patchfiles, you need only Subversion client itself. The proper command looks like this:
- When SVN command is used without extra options like above, it compares the working copy with its backup base. Note that diff (standalone or SVN) will see path relatively to the place where it's running, so it's better to launch it from trunk/vegastrike too, but narrow the scope as needed via parameters - in the example src/cmd/unit.cpp and all files in src/cmd/* are checked for differences, but nothing else.
~/repositories/VegaStrike/trunk/vegastrike$ svn diff src/cmd/ai src/cmd/unit.cpp >~/tmp/MyLatestVSPatch.patch
Revert patch
It's easy to revert a SVN working copy or its part to the original state, but it's also possible to un-apply patches one by one - at least, if the patched files aren't changed after the patch in question was applied:
or
~/repositories/VegaStrike/trunk/vegastrike$ patch -p0 -R -i ~/tmp/MyLatestVSPatch.patch
~/repositories/VegaStrike/trunk/vegastrike$ svn patch --reverse-diff ~/tmp/MyLatestVSPatch.patch