Contact me sending an e-mail (antispam defense activated)
HowTo use dpatch
Sandro Tosi, 17 September 2006
An important rules that every package maintainer should follow is to avoid directly upstream code modification.
The Right Way is to create a set of patches to be applied to upstream code at package build-time; this will let diff.gz contains only changes inside debian/ directory, which is a Good Thing.
A common tool to manage patches for packaging is dpatch.
0. Basic tasks
First of all, you have to install dpatch:
# apt-get install dpatch
and add dpatch to Build-Depends in debian/control . Moreover, you have to create the directory debian/patches: that will be the place where all patches will be stored.
In the same directory, there will be a file, debian/patches/00list: this will include a list of <patch_file_names> and the patches will be applied with the same order which are in that file.
1. Create a patch
The previous installed package, contains a useful tool, dpatch-edit-patch:
this will create a copy of source package, and will open a shell on that copy; do your changes and exit from the shell: file debian/patches/<patch_name> will be created with changes you've done.
Remember to update file debian/patches/00list.
A good practice is to add copyright note to patches: you can use a (example) policy where you put trivial patches on "public domain" and the program license for the ones you'd like to forward upstream.
2. Convert a patch
This script (thanks to Charles Plessy) takes modified and original file, creates a patch in unified format and then convert it to dpatch format.
diff -u source-tree-original/the-file source-tree/the-file | \
(replace <tags> with meaningful thing).
Usually patch (mainly the one sent throu BTS) are sent as a file: to convert such a patch, replace diff -u ... with cat /path/to/file.patch and that's all.
3. Test a patch
Ok, you've just forged a patch, but how to test if it does what it needs to do? Apply it!
From inside the extracted source package (the working copy for package creation) execute
and to revert
4. Use dpatch in debian/rules
Now, we have only left to instruct debian/rules to apply patches (in the order listed in debian/patches/00list) from debian/patches/ .
I think, the easiest way is to modify debian/rules this way:
But if you want, you can explicitly include patch/unpatch target as in this example:
Anyway, I suggest to follow the first way, which is cleaner a less error prone.
5. Restore pristine upstream code
The very first thing every Debian package maintainer has to rememeber is: NEVER change upstream code in your package, use patches. Even if you follow this Master Rule when packaging a tool by yourself, you may face upstream code changes when adopting a pacakge.
There is a way you can convert such changes (done by previous package maintainer) in a dpatch patch:
If you manage your packages the old way (no source code versioning system), you've done. I use Subversion to maintain my source packages, and that requires some additional steps:
It's a little bit complex, but this way you can adopt a package and use dpatch: that's good :)