[Linux-kernel-mentees] [PATCH] checkpatch: GIT_COMMIT_ID: handle commit messages with multiple quotes

Ayush ayush at disroot.org
Mon Sep 7 15:14:17 UTC 2020


Commits which mentioned/referenced "revert commits" in their description will
get error even if they follow the proper syntax.

for reference:
commit e8a170ff9a35 ("drm/amdgpu: enable -msse2 for GCC 7.1+ users")

This patch checks for quotes inside the commit message and adds it
to $orig_desc.

Earlier, the script just won't update in case of such commit message.
I modified old condition and added new conditions to check possible
patterns.

Following patters are solved (commit taken as example):
- commit 193392ed9f69 ("Revert "drm/amd/display: add -msse2 to prevent Clang from emitting libcalls to undefined SW FP routines"")

- commit 193392ed9f69 ("Revert
"drm/amd/display: add -msse2 to prevent Clang from emitting libcalls to undefined SW FP routines"")

- commit 193392ed9f69 ("Revert "drm/amd/display:
add -msse2 to prevent Clang from emitting libcalls to undefined SW FP routines"")

- commit 193392ed9f69
("Revert "drm/amd/display: add -msse2 to prevent Clang from emitting libcalls to undefined SW FP routines"")

Signed-off-by: Ayush <ayush at disroot.org>
---
 scripts/checkpatch.pl | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 149518d2a6a7..e90e13b013d3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2862,23 +2862,42 @@ sub process {
 				$orig_desc = $1;
 				$hasparens = 1;
 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
-				 defined $rawlines[$linenr] &&
-				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
+				 defined $rawlines[$linenr]) {
+				if ($rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
+					$orig_desc = $1;
+					$hasparens = 1;
+				} elsif ($rawlines[$linenr] =~ /^\s*\("([^"]+"[^"]+[^"]")"\)/) {
+					$orig_desc = $1;
+					$hasparens = 1;
+				}
+			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+				 defined $rawlines[$linenr]) {
+				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
 				$orig_desc = $1;
+				if($rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
+					$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
+					$orig_desc .= " " . $1;
 				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+				} elsif ($rawlines[$linenr] =~ /^\s*"[^"]+""\)/) {
+					$rawlines[$linenr] =~ /^\s*("[^"]+")"\)/;
+					$orig_desc .= " " . $1;
+					$hasparens = 1;
+				}
+			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+"[^"]+[^"]")"\)/i) {
+				$orig_desc = $1;
+			    $hasparens = 1;
+			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+"[^"]+$/i &&
 				 defined $rawlines[$linenr] &&
-				 $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
-				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
+				 $rawlines[$linenr] =~ /^\s*[^"]+""\)/) {
+				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+"[^"]+)$/i;
 				$orig_desc = $1;
-				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
+				$rawlines[$linenr] =~ /^\s*([^"]+")"\)/;
 				$orig_desc .= " " . $1;
 				$hasparens = 1;
 			}
 
 			($id, $description) = git_commit_info($orig_commit,
 							      $id, $orig_desc);

 			if (defined($id) &&
 			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
 				ERROR("GIT_COMMIT_ID",
-- 
2.28.0



More information about the Linux-kernel-mentees mailing list