From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <thomas.monjalon@6wind.com>
Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50])
 by dpdk.org (Postfix) with ESMTP id 4D8782C72
 for <dev@dpdk.org>; Thu,  2 Jun 2016 11:13:22 +0200 (CEST)
Received: by mail-wm0-f50.google.com with SMTP id z87so61145190wmh.0
 for <dev@dpdk.org>; Thu, 02 Jun 2016 02:13:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=6wind-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:subject:date:message-id;
 bh=XUQ9V93BVUZFq9qeqVkFn/l7SWGbCnc0GDWv+Xjavh0=;
 b=1pKvhUkxVqg6a2jv6KXpqsATT9JxMAGHcqg75sMvriLSrO3PfGZWtdzW8i3QCbHvm+
 o+JD7BiKMKdXOkFN/o1wdaAObFxjOE3P+f+B/7LJKLTddcViU52YqkrgKzKS5LhwWQZj
 2jDfuif47rlJk1Jqqanm2Gk5a3ZJc6xMRRe7PONxhqoFMIR/xwBOixcHKQeQKmOheGrw
 Bvl8gBWfirg5xgusL7UBupQBdtX6u3lPg7OLu6w6HeloGCH4HPkjYeHCYefjrwNl0AJJ
 heznoIQMb/Y24vPC5u6+uW9m1DvIQk9lDg1fsoLMQAFlcfp1R74Cp1DSZOKzBBhonnrC
 8Ymg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:subject:date:message-id;
 bh=XUQ9V93BVUZFq9qeqVkFn/l7SWGbCnc0GDWv+Xjavh0=;
 b=UtpJdpA6vjysnyzW67lonFAhAC688EGdQlmMrEoaIe0FzYH6GHt0P4thX7Hx8ZFwnY
 XeLk4y7cSPv7u3CECRa1zsF4icqn4WM9ijCsHXmoHvlTC/IdUKvyzAMQVOunXyhTZcPN
 wvq/Ow9xmWYwZs0M4clePExTGBfkoP1/R5jtwQt3/h+dZvWsyD+904ZaYOSwLSLzOQXf
 U80BSrdO+6EpzS2PO1QPOCHp0U2jF1mJHMzKjjN+IdrO8ABos39sQ6OMVhHA2xV4APXU
 D7K9RdOO09uKcikYcIUidEubIWycns87o967dIS/FCWA5YZji1WIEqsTO33VE/BgmE3+
 TiFw==
X-Gm-Message-State: ALyK8tJWrYyGxg44YDBNZff0g1qp/VQTxXaNtoP8HbQOVz+4pg1qxIx/ACXT9FGib/c1InGl
X-Received: by 10.28.144.7 with SMTP id s7mr23031826wmd.103.1464858802064;
 Thu, 02 Jun 2016 02:13:22 -0700 (PDT)
Received: from XPS13.enst.fr ([2001:660:330f:38:7e7a:91ff:fe14:f0d2])
 by smtp.gmail.com with ESMTPSA id e1sm49993241wjv.9.2016.06.02.02.13.20
 for <dev@dpdk.org> (version=TLSv1/SSLv3 cipher=OTHER);
 Thu, 02 Jun 2016 02:13:21 -0700 (PDT)
From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: dev@dpdk.org
Date: Thu,  2 Jun 2016 11:13:15 +0200
Message-Id: <1464858795-3152-1-git-send-email-thomas.monjalon@6wind.com>
X-Mailer: git-send-email 2.7.0
Subject: [dpdk-dev] [PATCH] scripts: check commits with checkpatch
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 02 Jun 2016 09:13:22 -0000

The new option -n allows to give a number of commits to check
from the git HEAD.
If neither -n nor patch files are given, the commits after
origin/master are checked.

Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 scripts/checkpatches.sh | 45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/scripts/checkpatches.sh b/scripts/checkpatches.sh
index 4cae86d..24a246d 100755
--- a/scripts/checkpatches.sh
+++ b/scripts/checkpatches.sh
@@ -48,17 +48,19 @@ NEW_TYPEDEFS,COMPARISON_TO_NULL"
 
 print_usage () {
 	cat <<- END_OF_HELP
-	usage: $(basename $0) [-q] [-v] [patch1 [patch2] ...]]
+	usage: $(basename $0) [-q] [-v] [-nX|patch1 [patch2] ...]]
 
 	Run Linux kernel checkpatch.pl with DPDK options.
 	The environment variable DPDK_CHECKPATCH_PATH must be set.
 	END_OF_HELP
 }
 
+number=0
 quiet=false
 verbose=false
-while getopts hqv ARG ; do
+while getopts hn:qv ARG ; do
 	case $ARG in
+		n ) number=$OPTARG ;;
 		q ) quiet=true && options="$options --no-summary" ;;
 		v ) verbose=true ;;
 		h ) print_usage ; exit 0 ;;
@@ -74,17 +76,42 @@ if [ ! -x "$DPDK_CHECKPATCH_PATH" ] ; then
 	exit 1
 fi
 
+total=0
 status=0
-for p in "$@" ; do
-	! $verbose || printf '\n### %s\n\n' "$p"
-	report=$($DPDK_CHECKPATCH_PATH $options "$p" 2>/dev/null)
+
+check () { # <patch> <commit> <title>
+	total=$(($total + 1))
+	! $verbose || printf '\n### %s\n\n' "$3"
+	if [ -n "$1" ] ; then
+		report=$($DPDK_CHECKPATCH_PATH $options "$1" 2>/dev/null)
+	elif [ -n "$2" ] ; then
+		report=$(git format-patch --stdout -1 $commit |
+			$DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
+	fi
 	[ $? -ne 0 ] || continue
-	$verbose || printf '\n### %s\n\n' "$p"
+	$verbose || printf '\n### %s\n\n' "$3"
 	printf '%s\n' "$report" | head -n -6
 	status=$(($status + 1))
-done
-pass=$(($# - $status))
-$quiet || printf '%d/%d valid patch' $pass $#
+}
+
+if [ -z "$1" ] ; then
+	if [ $number -eq 0 ] ; then
+		commits=$(git rev-list origin/master..)
+	else
+		commits=$(git rev-list --max-count=$number HEAD)
+	fi
+	for commit in $commits ; do
+		subject=$(git log --format='%s' -1 $commit)
+		check '' $commit "$subject"
+	done
+else
+	for patch in "$@" ; do
+		subject=$(sed -n 's,^Subject: ,,p' "$patch")
+		check "$patch" '' "$subject"
+	done
+fi
+pass=$(($total - $status))
+$quiet || printf '%d/%d valid patch' $pass $total
 $quiet || [ $pass -le 1 ] || printf 'es'
 $quiet || printf '\n'
 exit $status
-- 
2.7.0