HowTo:Apply Patch

From VsWiki
Revision as of 17:30, 16 July 2013 by Tbeholder (talk | contribs)
Jump to: navigation, search

Overview

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.

Linux

Create patch file

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 do at the proper base path (relatively to which path of each file is given, the same where diff was taken - usually trunk/vegastrike) and enter one command:
/your/working/copy/directory.../trunk/vegastrike$ patch -p0 -i /wherever/you/saved/that/patch.../PatchFileName.patch
- e.g.
~/repositories/VegaStrike/trunk/vegastrike$ patch -p0 -i ~/tmp/MyLatestVSPatch.patch
If everything worked, you'll get a report like
patching file src/cmd/unit_generic.h
patching file src/cmd/unit.cpp
patching file src/cmd/unit_generic.cpp
note that pathes here are relative to trunk/vegastrike.

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

To create patchfiles, you need something like
~/repositories/VegaStrike/trunk/vegastrike$ svn diff src/cmd >~/tmp/MyLatestVSPatch.patch
- When SVN command is used with defaults like this, it compares the working copy with its backup base. Note that diff, whether standalone or SVN, will see path relatively to the place where it's running, so launch it fromtrunk/vegastrike, but narrow the scope as needed with the parameters - in the example all files in src/cmd/* are checked for differences, and nothing else.

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.