From: christian.babeux@efficios.com (Christian Babeux)
Subject: [lttng-dev] [PATCH lttng-tools 3/3] Extras: Add a checkpatch git pre-commit hook to detect style issue
Date: Mon, 7 Jan 2013 17:12:42 -0500 [thread overview]
Message-ID: <1357596762-14132-3-git-send-email-christian.babeux@efficios.com> (raw)
In-Reply-To: <1357596762-14132-1-git-send-email-christian.babeux@efficios.com>
This commit add the checkpatch-hook script that can be installed in git
hooks folder in order to detect style issue before commiting any staged
changes.
The .checkpatch.conf file contains the appropriate options conforming to
the coding style used in the lttng-tools tree.
Also included in this commit is an install script to automatically
install the hook in the git local repo.
To override the pre-commit hook check, one can use the
`git commit --no-verify` command.
Signed-off-by: Christian Babeux <christian.babeux at efficios.com>
---
.gitignore | 2 ++
| 7 +++++++
| 30 ++++++++++++++++++++++++++++++
| 42 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 81 insertions(+)
create mode 100644 extras/.checkpatch.conf
create mode 100755 extras/checkpatch-hook
create mode 100755 extras/install-checkpatch-hook
diff --git a/.gitignore b/.gitignore
index 383dbf9..e61fd07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,8 @@ extras/bindings/swig/python/lttng.i
extras/bindings/swig/python/lttng.py
extras/bindings/swig/python/lttng_wrap.c
+.checkpatch.conf
+
# Tests
test_sessions
test_kernel_data_trace
--git a/extras/.checkpatch.conf b/extras/.checkpatch.conf
new file mode 100644
index 0000000..936f435
--- /dev/null
+++ b/extras/.checkpatch.conf
@@ -0,0 +1,7 @@
+# Not a kernel tree
+--no-tree
+
+# Ignore braces {} are not necessary for single statement blocks warning.
+# We enforce usage of {} even on single statement blocks.
+# See CodingStyles for more information.
+--ignore BRACES_SINGLE_STMT
--git a/extras/checkpatch-hook b/extras/checkpatch-hook
new file mode 100755
index 0000000..686815b
--- /dev/null
+++ b/extras/checkpatch-hook
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux at efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# To enable this hook, run the "install-checkpatch-hook" script.
+
+CHECKPATCH="extras/checkpatch.pl"
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+git diff --cached $against -- | $CHECKPATCH --no-signoff -
--git a/extras/install-checkpatch-hook b/extras/install-checkpatch-hook
new file mode 100755
index 0000000..9f0e985
--- /dev/null
+++ b/extras/install-checkpatch-hook
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux at efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Install the checkpatch pre-commit hook.
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+PRECOMMIT_HOOK="../.git/hooks/pre-commit"
+PRECOMMIT_SCRIPT="checkpatch-hook"
+CHECKPATCH_CONF=".checkpatch.conf"
+
+if [ -f $PRECOMMIT_HOOK ];
+then
+ echo "File $PRECOMMIT_HOOK already exists. Aborting."
+ exit 1
+else
+ ln -s $DIR/$PRECOMMIT_SCRIPT $PRECOMMIT_HOOK
+fi
+
+if [ -f ../$CHECKPATCH_CONF ];
+then
+ echo "File ../$CHECKPATCH_CONF already exists. Aborting."
+ exit 1
+else
+ ln -s $DIR/$CHECKPATCH_CONF ../$CHECKPATCH_CONF
+fi
+
+echo "Checkpatch pre-commit hook successfully installed!"
--
1.8.0.2
next prev parent reply other threads:[~2013-01-07 22:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 22:12 [lttng-dev] [PATCH lttng-tools 1/3] Extras: Add the checkpatch coding style script Christian Babeux
2013-01-07 22:12 ` [lttng-dev] [PATCH lttng-tools 2/3] Extras: Change TYPE of braces around single statement warning in checkpatch Christian Babeux
2013-01-07 22:12 ` Christian Babeux [this message]
2013-01-10 17:54 ` [lttng-dev] [PATCH lttng-tools 1/3] Extras: Add the checkpatch coding style script David Goulet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357596762-14132-3-git-send-email-christian.babeux@efficios.com \
--to=christian.babeux@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox