Patchwork checkpatch: add a little script to run checkpatch against a git refspec

login
register
mail settings
Submitter Anthony Liguori
Date Jan. 21, 2013, 4:48 p.m.
Message ID <1358786936-14818-1-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/214226/
State New
Headers show

Comments

Anthony Liguori - Jan. 21, 2013, 4:48 p.m.
This makes it easier to use checkpatch with a git hook or via patches.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 scripts/check-patches.sh | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100755 scripts/check-patches.sh
Peter Maydell - Jan. 21, 2013, 5:42 p.m.
On 21 January 2013 16:48, Anthony Liguori <aliguori@us.ibm.com> wrote:
> This makes it easier to use checkpatch with a git hook or via patches.

Any chance of a note in the comments about how to actually hook
it up to a git hook or patches? ie something like

# This script is intended to be used to allow checkpatch to
# be automatically run from a git hook or via the 'patches'
# tool [see http://link to download patches/], like this:
#
# [insert brief summary of how to hook it up here]

thanks
-- PMM
Anthony Liguori - Jan. 21, 2013, 7:21 p.m.
Peter Maydell <peter.maydell@linaro.org> writes:

> On 21 January 2013 16:48, Anthony Liguori <aliguori@us.ibm.com> wrote:
>> This makes it easier to use checkpatch with a git hook or via patches.
>
> Any chance of a note in the comments about how to actually hook
> it up to a git hook or patches? ie something like
>
> # This script is intended to be used to allow checkpatch to
> # be automatically run from a git hook or via the 'patches'
> # tool [see http://link to download patches/], like this:
> #
> # [insert brief summary of how to hook it up here]

That was sort of a theoritical statement.  Normally you would use a
pre-hook to do this and just use a git diff.  I assume you can use a
post-receive hook with this script but I'm not sure that's relevant to
anyone other than me.

Regards,

Anthony Liguori

>
> thanks
> -- PMM
Andreas Färber - Jan. 21, 2013, 8:05 p.m.
Am 21.01.2013 20:21, schrieb Anthony Liguori:
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
>> On 21 January 2013 16:48, Anthony Liguori <aliguori@us.ibm.com> wrote:
>>> This makes it easier to use checkpatch with a git hook or via patches.
>>
>> Any chance of a note in the comments about how to actually hook
>> it up to a git hook or patches? ie something like
>>
>> # This script is intended to be used to allow checkpatch to
>> # be automatically run from a git hook or via the 'patches'
>> # tool [see http://link to download patches/], like this:
>> #
>> # [insert brief summary of how to hook it up here]
> 
> That was sort of a theoritical statement.  Normally you would use a
> pre-hook to do this and just use a git diff.  I assume you can use a
> post-receive hook with this script but I'm not sure that's relevant to
> anyone other than me.

I'm been trying to use a pre-applypatch hook with checkpatch.pl but this
completely broke rebasing branches with false positives in them (which I
get quite a lot, especially related to pointer * spacing).

Right now I run a trivial script manually:

#!/bin/sh
git diff HEAD^ | ./scripts/checkpatch.pl --no-signoff -

Regards,
Andreas
Peter Maydell - Jan. 21, 2013, 9:14 p.m.
On 21 January 2013 19:21, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>> On 21 January 2013 16:48, Anthony Liguori <aliguori@us.ibm.com> wrote:
>>> This makes it easier to use checkpatch with a git hook or via patches.

>> Any chance of a note in the comments about how to actually hook
>> it up to a git hook or patches?

> That was sort of a theoritical statement.  Normally you would use a
> pre-hook to do this and just use a git diff.  I assume you can use a
> post-receive hook with this script but I'm not sure that's relevant to
> anyone other than me.

Well, the implication of putting the script into the qemu git repo
is that it's a useful tool for people other than you. So it should
be possible to add a brief description of how it's useful. If it's
not useful for anybody else then you should keep it in your own
local config :-)

-- PMM
Anthony Liguori - Jan. 21, 2013, 10:04 p.m.
Peter Maydell <peter.maydell@linaro.org> writes:

> On 21 January 2013 19:21, Anthony Liguori <aliguori@us.ibm.com> wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>> On 21 January 2013 16:48, Anthony Liguori <aliguori@us.ibm.com> wrote:
>>>> This makes it easier to use checkpatch with a git hook or via patches.
>
>>> Any chance of a note in the comments about how to actually hook
>>> it up to a git hook or patches?
>
>> That was sort of a theoritical statement.  Normally you would use a
>> pre-hook to do this and just use a git diff.  I assume you can use a
>> post-receive hook with this script but I'm not sure that's relevant to
>> anyone other than me.
>
> Well, the implication of putting the script into the qemu git repo
> is that it's a useful tool for people other than you. So it should
> be possible to add a brief description of how it's useful. If it's
> not useful for anybody else then you should keep it in your own
> local config :-)

$ scripts/check-patches.sh origin/master..HEAD

On your topic branch before submission.  I don't use commit hooks
because that would be annoying.

It's a darn simple script though so unless you don't know what a refspec
is it shouldn't need much explanation.

Regards,

Anthony Liguori

>
> -- PMM

Patch

diff --git a/scripts/check-patches.sh b/scripts/check-patches.sh
new file mode 100755
index 0000000..5a693fe
--- /dev/null
+++ b/scripts/check-patches.sh
@@ -0,0 +1,24 @@ 
+#!/bin/sh
+#
+# checkpatch helper - run checkpatch against each commit given a refspec
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+#  Anthony Liguori <aliguori@us.ibm.com>
+#
+# This work is licensed under the terms of the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+if test -z "$1"; then
+    echo "Usage: $0 REFSPEC"
+    exit 1
+fi
+
+git log --format="%H" "$@" | while read commit; do
+    git show --format=email $commit | scripts/checkpatch.pl -
+    rc=$?
+    if test $rc -ne 0; then
+	exit $rc
+    fi
+done