mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changbin Du <changbin.du@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: linux-kernel@vger.kernel.org, Changbin Du <changbin.du@gmail.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: [PATCH] checkpatch: warn on bad commit description in 'Fixes' tag
Date: Tue, 19 Feb 2019 06:36:11 +0000	[thread overview]
Message-ID: <20190219063611.19955-1-changbin.du@gmail.com> (raw)

There are some complaints about bad commit description in 'Fixes' tag.
Most cases are SHA1 should be at least 12 digits long. Let's extend
the existing check in checkpatch.pl to include commit description of
'Fixes' tag.

Reference: https://lkml.org/lkml/2019/2/18/1477
Signed-off-by: Changbin Du <changbin.du@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 scripts/checkpatch.pl | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b737ca9d7204..6f0156778a07 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2726,11 +2726,11 @@ sub process {
 		if ($in_commit_log && !$commit_log_possible_stack_dump &&
 		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i &&
 		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
-		    ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+                   ($line =~ /\b(?:commit|fixes:)\s+[0-9a-f]{5,}\b/i ||
 		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
 		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
 		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
-			my $init_char = "c";
+                       my $init_str = "commit";
 			my $orig_commit = "";
 			my $short = 1;
 			my $long = 0;
@@ -2742,29 +2742,29 @@ sub process {
 			my $orig_desc = "commit description";
 			my $description = "";
 
-			if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
-				$init_char = $1;
+                       if ($line =~ /\b(commit|fixes:)\s+([0-9a-f]{5,})\b/i) {
+                               $init_str = $1;
 				$orig_commit = lc($2);
 			} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
 				$orig_commit = lc($1);
 			}
 
-			$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
-			$long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
-			$space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
-			$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
-			if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
+                       $short = 0 if ($orig_commit =~ /\b[0-9a-f]{12,40}/i);
+                       $long = 1 if ($orig_commit =~ /\b[0-9a-f]{41,}/i);
+                       $space = 0 if ($line =~ /\b(?:commit|fixes:) [0-9a-f]/i);
+                       $case = 0 if ($line =~ /\b(?:Commit|commit|Fixes:)\s+[0-9a-f]{5,40}[^A-F]/);
+                       if ($line =~ /\b(?:commit|fixes:)\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
 				$orig_desc = $1;
 				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
+                       } elsif ($line =~ /\b(?:commit|fixes:)\s+[0-9a-f]{5,}\s*$/i &&
 				 defined $rawlines[$linenr] &&
 				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
 				$orig_desc = $1;
 				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+                       } elsif ($line =~ /\b(?:commit|fixes:)\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
 				 defined $rawlines[$linenr] &&
 				 $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
-				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
+                               $line =~ /\b(?:commit|fixes:)\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
 				$orig_desc = $1;
 				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
 				$orig_desc .= " " . $1;
@@ -2776,8 +2776,16 @@ sub process {
 
 			if (defined($id) &&
 			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+                               if (lc $init_str eq lc "commit") {
+                                       my @chars = split("", $init_str);
+                                       $init_str = "$chars[0]ommit";
+                               } else {
+                                       $init_str = "Fixes:"
+                               }
+
 				ERROR("GIT_COMMIT_ID",
-				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
+                                     "Please use git commit description style 'commit/Fixes: <12+ chars of sha1> (\"<title line>\")' - ie: '${init_str} $id (\"$description\")'\n" .
+                                     $herecurr . "\nThis can be fixed by 'git config --global core.abbrev 12'.\n");
 			}
 		}
 
-- 
2.17.1


             reply	other threads:[~2019-02-19  6:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19  6:36 Changbin Du [this message]
2019-02-19  9:22 ` Joe Perches

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=20190219063611.19955-1-changbin.du@gmail.com \
    --to=changbin.du@gmail.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sfr@canb.auug.org.au \
    --cc=torvalds@linux-foundation.org \
    /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

Powered by JetHome