Re: [Linux-kernel-mentees] [PATCH] checkpatch: GIT_COMMIT_ID: handle commit messages with multiple quotes
From: Joe Perches
Date: Mon Sep 07 2020 - 16:50:19 EST
On Mon, 2020-09-07 at 20:44 +0530, Ayush wrote:
> Commits which mentioned/referenced "revert commits" in their description will
> get error even if they follow the proper syntax.
I think all your examples are broken.
I think all should start with revert
i.e.: Reverts commit <SHA-1> ("description...")
> 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@xxxxxxxxxxx>
> ---
> 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",