scripts: add wrapper script for checkpatch
Add auxilary wrapper for convenient check of commit/
changes in staging area/multiple commits with checkpatch.pl
Put common functions for .travis.yml and checkpatch.sh into a
separate file
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
diff --git a/scripts/checkpatch.sh b/scripts/checkpatch.sh
new file mode 100755
index 0000000..94d8c4f
--- /dev/null
+++ b/scripts/checkpatch.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+DIR="${BASH_SOURCE%/*}"
+
+source "$DIR/checkpatch_inc.sh"
+
+hash $CHECKPATCH 2>/dev/null ||
+ { echo >&2 "Could not find checkpatch.pl, aborting"; exit 1; }
+
+usage() {
+ SCR=$(basename "$0")
+ echo "Usage: $SCR [--working] Check working area"
+ echo " $SCR <commit> Check specific commit"
+ echo " $SCR --diff <commit1> <commit2> Check diff commit1...commit2"
+ echo " $SCR --cached Check staging area"
+ echo " $SCR --help This help"
+ exit 1
+}
+
+op=${1:---working}
+case "$op" in
+ --cached)
+ echo "Checking staging area: "
+ checkstaging
+ ;;
+ --diff)
+ echo "Checking diff (diff $1...$2)"
+ checkdiff "$2" "$3"
+ ;;
+ --working)
+ echo "Checking working area: "
+ checkworking
+ ;;
+ --help|-h)
+ usage
+ ;;
+ *)
+ echo "Checking commit: "
+ checkpatch "$1"
+ ;;
+
+esac
diff --git a/scripts/checkpatch_inc.sh b/scripts/checkpatch_inc.sh
new file mode 100644
index 0000000..d88234e
--- /dev/null
+++ b/scripts/checkpatch_inc.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+CHECKPATCH=checkpatch.pl
+# checkpatch.pl will ignore the following paths
+CHECKPATCH_IGNORE=$(echo core/lib/lib{fdt,tomcrypt} lib/lib{png,utils,zlib})
+_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done)
+
+function _checkpatch() {
+ $CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \
+ --ignore GERRIT_CHANGE_ID --no-tree -
+}
+
+function checkpatch() {
+ git show --oneline --no-patch $1
+ git format-patch -1 $1 --stdout -- $_CP_EXCL . | _checkpatch
+}
+
+function checkstaging() {
+ git diff --cached -- . $_CP_EXCL | _checkpatch
+}
+
+function checkworking() {
+ git diff -- . $_CP_EXCL | _checkpatch
+}
+
+function checkdiff() {
+ git diff $1...$2 -- . $_CP_EXCL | _checkpatch
+}
+