Custom Search

Friday, March 21, 2014

How to use quilt to manage patches in Debian packages

http://raphaelhertzog.com/2012/08/08/how-to-use-quilt-to-manage-patches-in-debian-packages/

0)
#sudo apt-get install quilt
or
Install the packaging-dev package to get a decent set of packages to do Debian packaging. It includes the quilt package.
#sudo apt-get install packaging-dev

1)
Quilt manages a series of patches by keeping track of the changes each of them makes. They are logically organized as a stack, and you can apply, un-apply, update them easily by traveling into the stack (push/pop).

The “stack of patches” is maintained in a dedicated directory (“patches” by default, but in Debian packages we override this value to “debian/patches”). This directory contains the patch files and a “series” file that gives an ordered list of patches to apply.

When quilt is used, it also maintains some internal files in a directory of its own (it’s named “.pc”). This directory is used to know what patches are currently applied (.pc/applied-patches) and to keep backup copies of files modified by the various patches.

2)
Configuring quilt
--------------------
export QUILT_PATCHES=debian/patches

3)
Applying and unapplying patches, navigating in the stack of patches

a)
Apply next patch
#quilt push

b)
Apply all patch
#quilt push -a

c)
To see the name of applied patches
#quilt applied

d)
To see the name of next patch to be applied
#quilt next

e)
To see the name of unapplied pathes
#quilt unapplied

f)
Unapplies the last applied patch
#quilt pop

g)
Unapplies all applied patch
#quilt pop -a

h)
To see the name of last appled patch
#quilt top

i)
To apply up to particular patch
#quilt push name_ofpatch_file.diff

3)
How to Create a new patch
-----------------------------------------
If there’s no quilt series yet, you want to create the “debian/patches” directory first.
If you already have one, you need to decide where to insert the new patch. Quilt will always add the new patch just after the patch which is currently on top. So if you want to add the patch at the end of the series, you need to run “quilt push -a” first.
Then you can use quilt new name-of-my-patch.diff to tell quilt to insert a new empty patch after the current topmost patch. In this operation quilt does almost nothing except updating the series file and recording the fact that the new patch is applied (even if still empty at this point!).
Now to add changes in this patch, you’re supposed to modify files but only after having informed quilt of your intent to modify those files. You do this with quilt add file-to-modify. At this point quilt will make a backup copy of that file so that it can generate the final patch when you’re done with your changes. It’s quite common to forget this step and to be unable to generate the patch afterward. That’s why I recommend you to use quilt edit file-to-modify which is a shorthand for doing quilt add and then opening the file in your favorite text editor.
If you want, you can review your work in progress with quilt diff.
When you’re done with the changes, you should call quilt refresh to generate the patch (or to update it if it was already existing).

a)
if you want to add the patch at the end of the series, you need to run “quilt push -a” first
#quilt push -a

b)
add new patch file
#quilt new name-of-my-new-patch.diff

c)
Specify the files for which you want to create path
#quilt edit file-1-to-modify
#quilt edit file-2-to-modify
#quilt edit file-3-to-modify

d)
Open the files specified above in a text editor and make your changes

e)
How to review the patch before creating it
#quilt diff

f)
Generate the patch
#quilt refresh

4)
Importing an external patch
----------------------------
If someone else already prepared a patch, you can just import it right away with quilt import /tmp/the-patch. If you want to import it under a better name you can use the option “-P better-patch-name”. Like quilt new, it inserts the patch after the topmost patch.

a)
Import a new patch
#quilt import /tmp/the-name-of-patch-file.diff

b)
How to give new name for patch during import
#quilt import /tmp/the-name-of-patch-file.diff -P new-name-for-imported-patch-file.diff


5)
Updating patches for a new upstream version
--------------------------------------------
a)
Apply patches
#quilt push
or
#quilt push -a

b)
manually apply the parts of the patch that were rejected, and then refresh/generate the patch

c)
Generate the patch
#quilt refresh

6)
Other quilt commands
---------------------
a)
To rename the topmost patch
#quilt rename new-name-for-topmost-patch.diff

b)
To rename a particular patch
#quilt rename -P patch-to-rename.diff new-name-for-patch.diff

7)
Editing an existing patch
--------------------------
1)
cd horizon/debian

2)
export QUILT_PATCHES=debian/patches

3)
##Apply app patches
quilt push -a

4)
##Edit files / Make changes
vim ../openstack_dashboard/local/local_settings.py.example

5)
##Create patch
quilt refresh jcloud-settings.patch

6)
##Remove all applied patches
quilt pop -af

7)
Check
git diff

8)
git commit patches/jcloud-settings.patch

9)
quilt push -a
quilt pop -a




No comments:

Post a Comment