Skip to contentSkip to conversation

checkpatch: warn on bad commit description in 'Fixes' tag

PATCH In review Changbin Du 2 participants 2 messages Feb 19, 2019 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: warn on bad commit description in 'Fixes' tag

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

Cc Stephen Rothwell <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Steven Rostedt (VMware) <[email protected]>
---
 scripts/checkpatch.pl | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
scripts/checkpatch.pl +21 -13
index b737ca9d7204..6f0156778a07 100755
@@ -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");
 			}
 		}
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 4 lines · Changbin Du

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.

I sent a suggested patch a bit ago

https://lore.kernel.org/lkml/[email protected]/