Creating and Applying Patches

From Habari Project

Jump to: navigation, search

This page or image is a candidate for deletion. The given reason is: This page is a duplicate. It should be deleted in favour of Creating and Applying Patches for Subversion --drzax 00:30, 23 June 2010 (UTC)

This notice should remain for a minimum of 1 week after it was placed on the page. If discussion is still ongoing, it should remain until a consensus is reached, after which the page will either be deleted or this notice removed.

If you disagree with its deletion, please discuss your reasons on this page or on its associated talk page, as applicable.

Remember to check if anything links here and the page history before deleting.


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 .

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.

Creating patches

To create a patch (most commonly to attach to a ticket) you simply need to run svn diff on the files you wish to generate the patch for, and output that to a file.

svn diff /path/to/file.php > patch.diff

If you only have modifications to the the files you want included in the patch there is no need to specify the files, just do

svn diff > patch.diff

If you are generating a patch for a ticket I would suggest naming it patch_{ticket_number}.diff. If its the second iteration of a patch for that ticket, append _{iteration} to the name. So if I was creating the first patch for ticket #700, I'd call it patch_700.diff. If I then created an amended patch I would call it patch_700_2.diff.

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' 


Download Subversion

patch program for windows

Subversion Book

Other Development Pages · Developer Introduction
Personal tools