Subversion and applying patches
From Habari Project
Contents |
Using Subversion and applying patches
Subversion is a source code versioning system that allows developers to concurrently make changes to Habari's source code and reconcile any differences before a release is deployed.
Habari users have access to the current source code as being worked on by developers. Only those in the PMC have commit access and can commit changes back into the Habari subversion repository, but the repository is open to checkout for anonymous users.
To check out a copy of subversion to the current directory using the command line:
svn checkout http://svn.habariproject.org/habari/trunk/ .
To update an existing working copy to the latest code in the repository, execute this from the command line in the directory containing the working copy:
svn update
There are a number of graphical interfaces to interact with subversion for each operating system. These may be easier to use if you are not as familiar with running commands from the command line.
Testing patches that are not yet released
What are diff files ?
A diff file is the difference between a version of the source code in the repository and a working copy. It represents any changes, such as additional features or bug fixes, that have been made by a developer in a working copy. A diff file is generated using the svn diff command.
svn diff > descriptive_name_of_patch.diff
Applying diff files to your copy of habari
You can use the patch command to apply the diff file.
For windows systems, you can obtain a copy of patch from the gnuwin32 project
The common execution is patch -p0 < /path/to/file. This command will apply the differences that have been recorded in file to the appropriate file(s) in the current directory. As one diff file can contain changes for many files, and it preserves relative paths to sub-directories, the format of the diff file may affect where you need to invoke patch.
A practical example of diff and patch
predominantly from Scott Merrill's answer to Michael Bishop's question....
I modified a whole bunch of files for the Site class. When I was done editing, I changed to the htdocs directory of my checkout:
$ cd /home/skippy/code/habari/trunk/htdocs
I then executed svn status to see (and review) a list of all the files in my local copy that I have changed:
$ svn status
After double-checking the list of files, I executed svn diff to output a list of all the changes to all the files. I piped this output into a file:
$ svn diff > /tmp/site.diff
I attached the diff file to an email, or upload it to the Google issue tracker.
You read my email, and save my diff file. You transfer this file to your web host, which is running an SVN checkout of Habari. Because my diff was made from /trunk/htdocs, you should change to that directory in your local copy. (You may need to discern this from the contents of the diff file, if you don't know otherwise.)
Once in the target directory, you execute:
$ patch -p0 < /path/to/site.diff
The output of patch should report what it's doing:
skippy@skippy:~/code/habari/trunk/htdocs$ patch -p0 < /tmp/site.diff patching file system/admin/footer.php patching file system/admin/content.php patching file system/admin/dashboard.php patching file system/admin/header.php patching file system/classes/url.php patching file system/classes/site.php patching file system/classes/plugins.php patching file system/classes/feedbackhandler.php patching file system/classes/post.php patching file system/classes/options.php patching file system/classes/installhandler.php patching file system/classes/user.php patching file system/classes/controller.php patching file system/installer/db_setup.php patching file index.php patching file user/themes/k2/comments.php patching file user/themes/k2/header.php
If there are any problems, patch will report which file(s) failed. Figuring out what failed for each file, and why, can sometimes be challenging.
When you've determined that the patch works (or not!), and you want to go back to your vanilla Habari, you use the Subversion revert command. Using the "-R" (recursive) flag lets you easily revert your entire checkout to a clean state:
skippy@skippy:~/code/habari/trunk/htdocs$ svn -R revert * Skipped 'config.php' Reverted 'index.php' Reverted 'system/admin/footer.php' Reverted 'system/admin/content.php' Reverted 'system/admin/dashboard.php' Reverted 'system/admin/header.php' Reverted 'system/classes/url.php' Reverted 'system/classes/site.php' Reverted 'system/classes/plugins.php' Reverted 'system/classes/feedbackhandler.php' Reverted 'system/classes/post.php' Reverted 'system/classes/options.php' Reverted 'system/classes/installhandler.php' Reverted 'system/classes/user.php' Reverted 'system/classes/controller.php' Reverted 'system/installer/db_setup.php' Reverted 'user/themes/k2/comments.php' Reverted 'user/themes/k2/header.php'
