Creating patches with CVS
This page explains how to create patches using CVS diff. CVS diff compares your local files with a CVS repository. If you don't use CVS (or don't want to), you should consider a different patching method like diff (see main article on creating patches).
Before you start, please check the guidelines explained in the main article on Creating patches.
CVS Example
This assumes you have an up-to-date, clean CVS checkout of the Drupal files. (More help: set up CVS, check out Drupal core and check out contributed code.)
- Change your copy of the files and save them.
- Change into the proper "root" directory. For Drupal core:
cd /Applications/MAMP/htdocs/head. For contributed modules/themes:cd /Applications/MAMP/htdocs/6x/sites/all/modules/cck - Create a patch of your changes:
cvs diff -up > example.patch - Review your patch in a text editor.
- Post it to an issue on Drupal.org.
Changing CVS/Entries to add and remove files manually
If you're using -N to account for a new file, you'll also need to edit the CVS/Entries file for that directory and manually add a line for the new file. For example, if you have created a new file called newfile.inc in the modules/system directory, you will need to add a line at the end of the modules/system/CVS/Entries file like this:
Editing modules/system/CVS/Entries:
/admin.css/1.12/Tue Jan 16 23:15:28 2007//
/defaults.css/1.2/Fri Aug 25 09:01:12 2006//
/system.css/1.22/Wed Feb 7 03:46:21 2007//
/system.info/1.3/Tue Nov 21 20:55:35 2006//
/system.install/1.79/Fri Feb 16 16:39:46 2007//
/system.js/1.1/Thu Feb 22 16:33:29 2007//
/system.module/1.451/Thu Feb 22 16:33:29 2007//
/newfile.inc/0/New file//
If you are working from a tagged version the line will have the tag at the end. Use the other entries in the file to guide you:
/newfile.inc/0/New file//TDRUPAL-5
In this example, the "New file" string is arbitrary, but the 0 must be specified as the file's revision to show that it is new. Once this new line has been added cvs diff -Nup will properly include the new file in the diff.
Note: Do not add binary files (like PNG files) to a patch file. They will cause the testing system to fail with an “Invalid PHP syntax” error. If your patch requires additional binary files, simply post them as separate attachments to the issue and specify which directory they should go in.
If you are using -N to account for a deleted file, you will also need to edit the CVS/Entries file for that directory and manually change the line for the removed file. For example, if you want to remove system.module in the modules/system directory, you will need to modify the corresponding of the modules/system/CVS/Entries file like this:
/admin.css/1.12/Tue Jan 16 23:15:28 2007//
/defaults.css/1.2/Fri Aug 25 09:01:12 2006//
/system.css/1.22/Wed Feb 7 03:46:21 2007//
/system.info/1.3/Tue Nov 21 20:55:35 2006//
/system.install/1.79/Fri Feb 16 16:39:46 2007//
/system.js/1.1/Thu Feb 22 16:33:29 2007//
/system.module/-1.451/Thu Feb 22 16:33:29 2007//
That's it! all you need to do is add a - to the version, so 1.451 becomes -1.451. (This works for files only—not directories).
Adding directories
It is also possible to use cvs patches to add a directory. For example, to add an add-on module to an existing module.
- Within a directory that cvs knows about, add a new file to cvs shown above. With contributed modules, this would be in the root directory of that module.
- Create the patch file by modifying CVS/Entries and using the -N switch shown above.
- Edit the patch file adding the directory path that the files should reside in.
- Example shown below, the first part shows the first few lines of the patch file created in the module root, after editing, I manually add 'contrib/exhibit_apachesolr' in front of any reference to the new file.
- After running the patch file, on a cvs checked out module, it creates both the file exhibit_apachesolr.info inside the created directory exhibit_apachesolr (that resides under contrib).
Index: exhibit_apachesolr.info
==============================================================
RCS file: exhibit_apachesolr.info
diff -N exhibit_apachesolr.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ exhibit_apachesolr.info 8 Nov 2008 16:18:41 -0000Index: contrib/exhibit_apachesolr/exhibit_apachesolr.info
==============================================================
RCS file: contrib/exhibit_apachesolr/exhibit_apachesolr.info
diff -N contrib/exhibit_apachesolr/exhibit_apachesolr.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/exhibit_apachesolr/exhibit_apachesolr.info 8 Nov 2008 16:18:41 -0000An example using cvs diff
- Make sure you have the latest CVS version of the file(s) before you begin making your changes: change (
cd) to the Drupal root directory and run the update command:cvs update -dP. - Make your changes to the file(s).
- When you are ready to roll your patch, change back to the Drupal root directory.
- Do a
cvs diff -up path/to/file/example.module > mypatchname.patch. This creates a new patch file in the Drupal root that you can now upload to an issue.
