linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v2] checkpatch: handle line break between commit and hash value
@ 2020-09-12  9:48 Ayush
  2020-09-12 11:17 ` Lukas Bulwahn
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Ayush @ 2020-09-12  9:48 UTC (permalink / raw)
  To: lukas.bulwahn; +Cc: linux-kernel-mentees

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@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

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-09-17 15:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-12  9:48 [Linux-kernel-mentees] [PATCH v2] checkpatch: handle line break between commit and hash value Ayush
2020-09-12 11:17 ` Lukas Bulwahn
2020-09-12 12:42 ` Lukas Bulwahn
2020-09-12 13:34 ` Ayush
2020-09-12 14:15 ` Lukas Bulwahn
2020-09-12 15:38 ` Ayush
2020-09-12 19:37 ` Ayush
2020-09-13 11:01   ` Lukas Bulwahn
2020-09-13 12:06   ` Ayush
2020-09-13 18:09     ` Lukas Bulwahn
2020-09-13 20:53     ` Ayush
2020-09-14  5:12       ` Lukas Bulwahn
2020-09-17 14:53       ` Ayush
2020-09-17 15:17         ` Lukas Bulwahn

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox