[PATCH] checkpatch: Add the backport commit format check

korantwork@gmail.com posted 1 patch 2 years, 9 months ago
scripts/checkpatch.pl | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
[PATCH] checkpatch: Add the backport commit format check
Posted by korantwork@gmail.com 2 years, 9 months ago
From: Xinghui Li <korantli@tencent.com>

The backport commit has been  used to be misreported as Error
by checkpatch.pl like this:

'ERROR: Please use git commit description style
'commit <12+ chars of sha1> ("<title line>")' - ie:......
commit <sha1> upstream.

total: 1 errors, 0 warnings, 8 lines checked
'
So, add the backport commit format check to avoid the above mistake.

Signed-off-by: Xinghui Li <korantli@tencent.com>
---
 scripts/checkpatch.pl | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1e5e66ae5a52..92ba39418239 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3252,6 +3252,10 @@ sub process {
 # A correctly formed commit description is:
 #    commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
 # with the commit subject '("' prefix and '")' suffix
+# A correctly formed backport commit description is:
+#	commit <sha1> upstream.
+# or
+#	[ Upstream commit <sha1> ]
 # This is a fairly compilicated block as it tests for what appears to be
 # bare SHA-1 hash with  minimum length of 5.  It also avoids several types of
 # possible SHA-1 matches.
@@ -3278,6 +3282,7 @@ sub process {
 			my $herectx = $herecurr;
 			my $has_parens = 0;
 			my $has_quotes = 0;
+			my $backport = 0;
 
 			my $input = $line;
 			if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
@@ -3307,18 +3312,21 @@ sub process {
 				$long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
 				$space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
 				$case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+				$backport = 1 if(($input =~ /\bcommit\s+[0-9a-f]{12,40}\supstream/i) ||
+								 ($input =~ /\B\[\s[Uu]pstream\scommit\s+[0-9a-f]{5,}\s\]/));
 			} elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
 				$orig_commit = lc($1);
 			}

 			($id, $description) = git_commit_info($orig_commit,
 							      $id, $orig_desc);
 
 			if (defined($id) &&
 			    ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
-			    $last_git_commit_id_linenr != $linenr - 1) {
+			    $last_git_commit_id_linenr != $linenr - 1
+			    && !$backport) {
 				ERROR("GIT_COMMIT_ID",
-				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
+				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\nor check the backport commit description format\n" . $herectx);
 			}
 			#don't report the next line if this line ends in commit and the sha1 hash is the next line
 			$last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
-- 
2.27.0
Re: [PATCH] checkpatch: Add the backport commit format check
Posted by Joe Perches 2 years, 9 months ago
On Mon, 2022-12-05 at 17:48 +0800, korantwork@gmail.com wrote:
> From: Xinghui Li <korantli@tencent.com>
> 
> The backport commit has been  used to be misreported as Error
> by checkpatch.pl like this:
> 
> 'ERROR: Please use git commit description style
> 'commit <12+ chars of sha1> ("<title line>")' - ie:......
> commit <sha1> upstream.
> 
> total: 1 errors, 0 warnings, 8 lines checked
> '
> So, add the backport commit format check to avoid the above mistake.

nak.

I don't believe this should be an accepted style.

and

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
>  				ERROR("GIT_COMMIT_ID",
> -				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
> +				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\nor check the backport commit description format\n" . $herectx);

Output messages are only single line not multiple lines.
Re: [PATCH] checkpatch: Add the backport commit format check
Posted by Xinghui Li 2 years, 9 months ago
在 2022/12/5 20:46,“Joe Perches”<joe@perches.com> 写入:
>    nak.
>
>   I don't believe this should be an accepted style.

Sorry for my confusion between LTS and mainline.

Thanks for your reply.