«

»

Oct
14

How to create patches using quilt

Last time I described how to contribute quite to any package in openSUSE Build Service. But I left out the most important part. I haven’t shown how to change anything. This time I want to show you, how to create patches, if you need them, easily. Let’s start start with package we checked out from obs. Creating patch for anything is different only in first few steps.
First we got to the directory where do we have the package checked out. We run

quilt setup

This command will parse the .spec file, unpack tarball and prepare all quilt stuff. Now is time for patching, so let’s enter the newly created directory and try following command

quilt push

You know that in .spec there might be some patches. quilt push will take first patch that is not applied yet and apply it. If you want to go back, you can use quilt pop. You can also use quilt patch -a to apply all patches if possible. If it is not possible, it will tell you loudly and you have to handle situation manually. This often happens when you are updating package to the newer version.
How to deal with it? Trick is to start with quilt patch -f which will apply everything it can and tell you about stuff that can’t be applied (and creates bunch of .rej files. Now you have to fix these, but you are already working on patch, so just skip following paragraph and continue with howto ;-)
If all patches applied without problems/you don’t have any yet, you have to start one. You can also start here, if you don’t have a spec file and you just want to create a patch for some sources that were lying on your hard drive. You can start new patch by calling

quilt new package-version-patch-name.patch

From now you are working on patch. As patch consists from changes to the files, you have to do that changes now, right? One easy way is to call

quilt edit path/file

This will open up you favorite editor (the one that is set in your EDITOR variable) and open up specified file and let you edit it. You can also do a little bit different trick. You can use

quilt add path/file

This just saves the current state of the file. You can then edit it how ever you want or replace it with another file or do some changes to it however you want.
Once you are done with editing, it’s time to actually create a patch. You can review all changes by using quilt diff and if you are happy with them, call

quilt refresh -p0

This will create patch with patch level 0 (this is the best choice for .spec files, git creates patch level 1 by default). It will also tell you where your patch is. So you can just take it and use it.
Last little note, as I already pointed out, you can of course use quilt not only with .spec files. You can enter any directory anywhere and start creating patch using quilt new patchname.patch, quilt edit path/file and quilt refresh -p0. It will work too. quilt setup and quilt push are just great help to apply all patches that you have already prepared and continue from there.
Hope this may help some of you with patching software and playing with packaging. Next time, I’ll continue with how do I package MySQL on openSUSE in more details and how do I handle all different variants.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>