Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333AbcDXXMY (ORCPT ); Sun, 24 Apr 2016 19:12:24 -0400 Received: from smtprelay0143.hostedemail.com ([216.40.44.143]:55531 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753191AbcDXXMW (ORCPT ); Sun, 24 Apr 2016 19:12:22 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1345:1437:1534:1543:1605:1711:1730:1747:1777:1792:1801:2393:2559:2562:3138:3139:3140:3141:3142:3653:3865:3866:3867:3868:3871:3872:4250:4321:4605:5007:6119:6261:6299:7807:7903:8603:8957:9040:9121:9163:10004:10848:11232:11233:11658:11914:12043:12291:12517:12519:12555:12683:13095:14181:14394:14721:21080:30054:30062:30064:30070,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: bears60_4ea2cad91b41b X-Filterd-Recvd-Size: 4644 From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: "Du, Changbin" , linux-kernel@vger.kernel.org Subject: [PATCH] checkpatch: Add support to check already applied git commits Date: Sun, 24 Apr 2016 16:12:19 -0700 Message-Id: <8a509a881fbf54b3a7e870bd1655688260ea47a7.1461539133.git.joe@perches.com> X-Mailer: git-send-email 2.8.0.rc4.16.g56331f8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3873 Lines: 118 It's sometimes useful to scan already committed patches. Add --git to scan specific or multiple commits. Single commits are scanned with --git Multiple commits are scanned with --git --git - Signed-off-by: "Du, Changbin" Signed-off-by: Joe Perches --- A few miscellaneous improvements to Changbin's original patch: o Don't exec git for each -, use a single "git log - " o Consolidate the git exec for the and - variants o Output 12 character commit hash ids o Don't scan git commit merges o Use -M to reduce the size of rename commits scripts/checkpatch.pl | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e3d9c34..1bba191 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -27,6 +27,7 @@ my $emacs = 0; my $terse = 0; my $showfile = 0; my $file = 0; +my $git = 0; my $check = 0; my $check_orig = 0; my $summary = 1; @@ -68,6 +69,16 @@ Options: --emacs emacs compile window format --terse one line per report --showfile emit diffed file position, not input file position + -g, --git treat FILE as a single commit or git revision range + single git commit with: + + ^ + ~n + multiple git commits with: + .. + ... + - + git merges are ignored -f, --file treat FILE as regular source file --subjective, --strict enable more subjective tests --types TYPE(,TYPE2...) show only these comma separated message types @@ -141,6 +152,7 @@ GetOptions( 'terse!' => \$terse, 'showfile!' => \$showfile, 'f|file!' => \$file, + 'g|git!' => \$git, 'subjective!' => \$check, 'strict!' => \$check, 'ignore=s' => \@ignore, @@ -752,10 +764,42 @@ my @fixed_inserted = (); my @fixed_deleted = (); my $fixlinenr = -1; +# If input is git commits, extract all commits from the commit expressions. +# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'. +die "$P: No git repository found\n" if ($git && !-e ".git"); + +if ($git) { + my @commits = (); + for my $commit_expr (@ARGV) { + my $git_range; + if ($commit_expr =~ m/-/) { + my @tmp = split(/-/, $commit_expr); + die "$P: incorrect git commits expression $commit_expr$!\n" + if (@tmp != 2); + $git_range = "-$tmp[1] $tmp[0]"; + } elsif ($commit_expr =~ m/\.\./) { + $git_range = "$commit_expr"; + } + if (defined $git_range) { + my $lines = `git log --no-merges --pretty=format:'%H' $git_range`; + foreach my $line (split(/\n/, $lines)) { + unshift(@commits, $line); + } + } else { + unshift(@commits, $commit_expr); + } + } + die "$P: no git commits after extraction!\n" if (@commits == 0); + @ARGV = @commits; +} + my $vname; for my $filename (@ARGV) { my $FILE; - if ($file) { + if ($git) { + open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || + die "$P: $filename: git format-patch failed - $!\n"; + } elsif ($file) { open($FILE, '-|', "diff -u /dev/null $filename") || die "$P: $filename: diff failed - $!\n"; } elsif ($filename eq '-') { @@ -766,6 +810,8 @@ for my $filename (@ARGV) { } if ($filename eq '-') { $vname = 'Your patch'; + } elsif ($git) { + $vname = "Commit " . substr($filename, 0, 12) . `git log -1 --pretty=format:' ("%s")' $filename`; } else { $vname = $filename; } -- 2.8.0.rc4.16.g56331f8