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...@gmail.com>
Cc: Stephen Rothwell <s...@canb.auug.org.au>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Steven Rostedt (VMware) <rost...@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 via email to