[Linux-kernel-mentees] [PATCH v2] checkpatch: handle line break between commit and hash value

Ayush ayush at disroot.org
Sat Sep 12 09:48:26 UTC 2020


checkpatch.pl checks for proper references to other commits with
the intended format, commit <12+ characters of SHA-1 ID> ("<commit
message") and warns about typical mistakes. Currently, it does
not handle the case where there is a line break between commit and the
hash value.
It falsely warns that the hash is not prefixed by the word commit.

This adds new conditions to parse and identify such commits and
to not report an error in such cases.

following type of commit reference is handled:

- commit
f4d51dffc6c01 ("Linux 5.9-rc4")

This issue was discovered through a thorough analysis of checkpatch.pl
errors and warnings of type GIT_COMMIT_ID on commits between v5.7 and v5.8.

Before applying this patch, checkpatch.pl reported 342 errors of type
GIT_COMMIT_ID. After applying patch, errors reduced to 284.

Signed-off-by: Ayush <ayush at disroot.org>
---
Change in v2:
    - Add conditions to check and not report error if "commit" is last
      word of line.
    - Remove handling of multiple quotes in commit message (Will be
      added in another patch).
    - If a line break is encountered between commit and hash value, then
      it will again check for next line (starting with hash) and report 
      error. Add a condition to skip checking next line.

 scripts/checkpatch.pl | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 149518d2a6a7..42de3939a445 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -68,7 +68,7 @@ my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANC
 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
 my $tabsize = 8;
 my ${CONFIG_} = "CONFIG_";
-
+my $c_count = 0;
 sub help {
 	my ($exitcode) = @_;
 
@@ -2831,8 +2831,9 @@ sub process {
 		if ($in_commit_log && !$commit_log_possible_stack_dump &&
 		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
 		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
-		    ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
-		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
+		    (($line =~ /\bcommit$/i && ($rawlines[$linenr] =~ /^[0-9a-f]{5,}/i))||
+		     $line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+		     ((($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i) && ($c_count++ != 1)) &&
 		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
 		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
 			my $init_char = "c";
@@ -2846,12 +2847,15 @@ sub process {
 			my $id = '0123456789ab';
 			my $orig_desc = "commit description";
 			my $description = "";
+			$c_count = 0;
 
 			if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
 				$init_char = $1;
 				$orig_commit = lc($2);
 			} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
 				$orig_commit = lc($1);
+			} elsif ($rawlines[$linenr] =~ /^([0-9a-f]{12,40})\b/i) {
+				$orig_commit = lc($1);
 			}
 
 			$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
@@ -2874,6 +2878,17 @@ sub process {
 				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
 				$orig_desc .= " " . $1;
 				$hasparens = 1;
+			} elsif ($line =~ /\bcommit$/i &&
+				 defined $rawlines[$linenr]) {
+				if($rawlines[$linenr] =~ /\b[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
+					$orig_desc = $1;
+				}
+				$hasparens = 1;
+				$space = 0;
+				$short = 0 if ($rawlines[$linenr] =~ /^[0-9a-f]{12,40}/i);
+				$long = 1 if ($rawlines[$linenr] =~ /^[0-9a-f]{41,}/i);
+				$case = 0 if ($rawlines[$linenr] =~ /^[0-9a-f]{5,40}[^A-F]/i);
+				$c_count = 1;
 			}
 
 			($id, $description) = git_commit_info($orig_commit,
-- 
2.28.0



More information about the Linux-kernel-mentees mailing list