Quilt: a quick primer



Quilt is a handy tool to manage patches, and I discovered its value while porting a router to a newer OpenWrt version. The diff from the 14.07 codebase would apply with some adjustments, but patch would still give some messages about offsets etc.:

$ patch -Np1 -i ../patch
patching file target/linux/ar71xx/base-files/etc/diag.sh
Hunk #1 succeeded at 215 with fuzz 2.
Hunk #2 succeeded at 362 with fuzz 1 (offset -3 lines).
patching file target/linux/ar71xx/base-files/etc/uci-defaults/02_network
patching file target/linux/ar71xx/base-files/lib/upgrade/platform.sh
patching file target/linux/ar71xx/base-files/lib/ar71xx.sh
Hunk #2 succeeded at 323 with fuzz 2 (offset -3 lines).
patching file target/linux/ar71xx/config-3.18
Hunk #1 succeeded at 68 with fuzz 1 (offset 13 lines).
[...]

For a better overview (and to find out a bit quicker what breaks where), you can get rid of those messages. You could start correcting those line numbers manually in the patch but that's tedious and error-prone. That's where quilt comes in handy; however it doesn't always play nice and honour strip levels in your patches. So we'll regerenate the patch through quilt.

First, you tell quilt to create a new patch:

$ quilt new add-minibox.patch

Then, you tell quilt which files it needs to keep track of:

$ quilt add target/linux/ar71xx/base-files/etc/diag.sh target/linux/ar71xx/base-files/etc/uci-defaults/02_network
target/linux/ar71xx/base-files/lib/upgrade/platform.sh target/linux/ar71xx/base-files/lib/ar71xx.sh 
target/linux/ar71xx/config-4.1 target/linux/ar71xx/files/arch/mips/ath79/mach-minibox-v1.c 
target/linux/ar71xx/generic/profiles/minibox-v1.mk target/linux/ar71xx/image/Makefile 
target/linux/ar71xx/patches-4.1/799-MIPS-ath79-add-minibox-v1-support.patch

After that, apply the old patch and tell quilt to generate the new one:

$ patch -Np1 -i ../patch
$ quilt refresh

At this point, you will have your new add-minibox.patch in patches/. Now, if we revert the old patch, and apply the new diff, you'll see the messages are gone:

$ patch -R -Np -i ../patch
$ patch -Np2 -i ../patches/add-minibox-target-trunk.patch 
patching file target/linux/ar71xx/base-files/etc/diag.sh
patching file target/linux/ar71xx/base-files/etc/uci-defaults/02_network
patching file target/linux/ar71xx/base-files/lib/ar71xx.sh
patching file target/linux/ar71xx/base-files/lib/upgrade/platform.sh
patching file target/linux/ar71xx/config-4.1
patching file target/linux/ar71xx/files/arch/mips/ath79/mach-minibox-v1.c
patching file target/linux/ar71xx/generic/profiles/minibox-v1.mk
patching file target/linux/ar71xx/image/Makefile
patching file target/linux/ar71xx/patches-4.1/799-MIPS-ath79-add-minibox-v1-support.patch
$