[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]

Check Patches with Quilt

Thu, 16 Apr 2009

Linux kernel developers adhere to a coding style, documented in Documentation/CodingStyle. Patches submitted to the Linux kernel, should comply with the style. The kernel tree has a Perl script scripts/checkpatch.pl that can be used for checking style violations. People who use quilt to manage their patches might find it convenient if the style checking facility is built to quilt. So for example to check the topmost patch, one would just do

$ quilt check

It turns out this is not hard after all.

All quilt sub-commands are scripts located at /usr/share/quilt (referred to as $QUILT_DIR). To implement your own sub-command just add a script to this directory. I started with a very simple quilt sub-command top and made the following changes to create check.

--- top         2006-11-27 15:05:03.000000000 +0530
+++ check       2009-04-12 19:05:41.000000000 +0530
@@ -19,12 +19,11 @@

-       printf $"Usage: quilt top\n"
+       printf $"Usage: quilt check\n"
        if [ x$1 = x-h ]
                printf $"
-Print the name of the topmost patch on the current stack of applied
+Run checkpatch.pl on the topmost patch.
                exit 0
@@ -58,7 +57,16 @@

 top=$(find_top_patch) || exit 2
-echo "$(print_patch $top)"
+top_file=$(patch_file_name $top)
+if [ -e $checkpatch ];
+    $checkpatch --emacs --strict $top_file
+    echo "checkpatch.pl not found. Is this a kernel tree?"
+    exit 1

 ### Local Variables:
 ### mode: shell-script

The changes are fairly straight forward. quilt has a library of useful functions in $QUILT_DIR/scripts/patchfns. The library is included in all sub-commands as the first step. The library inclusion is not shown in the above patch.

Instead of printing the topmost patch, the following operations are performed.

  1. We determine the filename of the patch using the patch_file_name function.

  2. quilt's patches directory path is available using $QUILT_PATCHES variable. We check if the checkpatch.pl is present, by looking for a file $QUILT_PATCHES/../scripts/checkpatch.pl. Note that, here we are assuming that quilt's patches directory is located at the Linux kernel’s root directory.

  3. We then invoke checkpatch.pl with the patch filename as argument.

Further Ideas

This can be taken a little further and the refresh sub-command can be modified to perform the check after refreshing the patch. This could be the default behaviour of the refresh sub-command, or the behaviour could be invoked through an option to refresh.

Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: linux-kernel

blog comments powered by Disqus

Powered by Python | Made with PyBlosxom | Valid XHTML 1.1 | Best Viewed With Any Browser | Icon Credits | CC-BY-SA