2022-08-29 16:03:24

by Niklas Söderlund

[permalink] [raw]
Subject: [PATCH] checkpatch: warn for non-standard fixes tag style

Add a warning for fixes tags that does not fall in line with the
standards specified by the community.

Signed-off-by: Niklas Söderlund <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Reviewed-by: Louis Peens <[email protected]>
---
Documentation/dev-tools/checkpatch.rst | 6 ++++
scripts/checkpatch.pl | 41 ++++++++++++++++++++++++++
2 files changed, 47 insertions(+)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index b52452bc2963..8164f362a2fc 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -612,6 +612,12 @@ Commit message

See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

+ **BAD_FIXES_TAG**
+ The fixes line does not fall in line with the standards specified by the
+ community.
+
+ See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
+

Comparison style
----------------
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 79e759aac543..9b8cdc582fb5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3140,6 +3140,47 @@ sub process {
}
}

+# Check Fixes: styles is correct
+ if (!$in_header_lines && $line =~ /^fixes:/i) {
+ my $orig_commit = "";
+ my $id = "0123456789ab";
+ my $title = "commit title";
+ my $tag_case = 1;
+ my $tag_space = 1;
+ my $id_length = 1;
+ my $id_case = 1;
+ my $title_has_quotes = 0;
+
+ if ($line =~ /(fixes:)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {
+ my $tag = $1;
+ $orig_commit = $2;
+ $title = $3;
+
+ $tag_case = 0 if $tag eq "Fixes:";
+ $tag_space = 0 if ($line =~ /^fixes: [0-9a-f]{5,} ($balanced_parens)/i);
+
+ $id_length = 0 if ($orig_commit =~ /^[0-9a-f]{12}$/i);
+ $id_case = 0 if ($orig_commit !~ /[A-F]/);
+
+ # Always strip leading/trailing parens then double quotes if existing
+ $title = substr($title, 1, -1);
+ if ($title =~ /^".*"$/) {
+ $title = substr($title, 1, -1);
+ $title_has_quotes = 1;
+ }
+ }
+
+ ($id, $title) = git_commit_info($orig_commit, $id,
+ $title);
+
+ if ($tag_case || $tag_space || $id_length || $id_case ||
+ !$title_has_quotes) {
+ WARN("BAD_FIXES_TAG",
+ "Please use correct Fixes: style 'Fixes: <12 chars of sha1> (\"<title line>\")' - ie: 'Fixes: $id (\"$title\")'\n" . $herecurr);
+
+ }
+ }
+
# Check email subject for common tools that don't need to be mentioned
if ($in_header_lines &&
$line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
--
2.37.2


2022-08-30 03:17:39

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: warn for non-standard fixes tag style

On Mon, 2022-08-29 at 17:53 +0200, Niklas S?derlund wrote:
> Add a warning for fixes tags that does not fall in line with the
> standards specified by the community.
>
> Signed-off-by: Niklas S?derlund <[email protected]>
> Reviewed-by: Simon Horman <[email protected]>
> Reviewed-by: Louis Peens <[email protected]>
> ---
> Documentation/dev-tools/checkpatch.rst | 6 ++++
> scripts/checkpatch.pl | 41 ++++++++++++++++++++++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
> index b52452bc2963..8164f362a2fc 100644
> --- a/Documentation/dev-tools/checkpatch.rst
> +++ b/Documentation/dev-tools/checkpatch.rst
> @@ -612,6 +612,12 @@ Commit message
>
> See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
>
> + **BAD_FIXES_TAG**
> + The fixes line does not fall in line with the standards specified by the
> + community.
> +
> + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
> +
>
> Comparison style
> ----------------
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 79e759aac543..9b8cdc582fb5 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3140,6 +3140,47 @@ sub process {
> }
> }
>
> +# Check Fixes: styles is correct
> + if (!$in_header_lines && $line =~ /^fixes:/i) {
> + my $orig_commit = "";
> + my $id = "0123456789ab";
> + my $title = "commit title";
> + my $tag_case = 1;
> + my $tag_space = 1;
> + my $id_length = 1;
> + my $id_case = 1;
> + my $title_has_quotes = 0;
> +
> + if ($line =~ /(fixes:)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {

Maybe use fixes:? so the colon is not required in poorly formed uses

> + my $tag = $1;
> + $orig_commit = $2;
> + $title = $3;
> +
> + $tag_case = 0 if $tag eq "Fixes:";
> + $tag_space = 0 if ($line =~ /^fixes: [0-9a-f]{5,} ($balanced_parens)/i);

fixes:? here too

Pity there's no simple way to consolidate this git commit test block
with the existing git id commit block.

> +
> + $id_length = 0 if ($orig_commit =~ /^[0-9a-f]{12}$/i);
> + $id_case = 0 if ($orig_commit !~ /[A-F]/);
> +
> + # Always strip leading/trailing parens then double quotes if existing
> + $title = substr($title, 1, -1);
> + if ($title =~ /^".*"$/) {
> + $title = substr($title, 1, -1);
> + $title_has_quotes = 1;
> + }
> + }
> +
> + ($id, $title) = git_commit_info($orig_commit, $id,
> + $title);
> +
> + if ($tag_case || $tag_space || $id_length || $id_case ||
> + !$title_has_quotes) {
> + WARN("BAD_FIXES_TAG",
> + "Please use correct Fixes: style 'Fixes: <12 chars of sha1> (\"<title line>\")' - ie: 'Fixes: $id (\"$title\")'\n" . $herecurr);
> +
> + }
> + }
> +
> # Check email subject for common tools that don't need to be mentioned
> if ($in_header_lines &&
> $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {

2022-08-30 03:44:12

by Bagas Sanjaya

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: warn for non-standard fixes tag style

On 8/29/22 22:53, Niklas Söderlund wrote:
> + **BAD_FIXES_TAG**
> + The fixes line does not fall in line with the standards specified by the
> + community.
> +
> + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
> +
>

Did you mean "The Fixes: tag is malformed"?

Also, mention that this message can occur when the tag is split
into multiple lines (e.g., when pasted in email program with word
wrapping enabled).

Thanks.

--
An old man doll... just what I always wanted! - Clara

2022-09-05 11:55:47

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: warn for non-standard fixes tag style

Hi Joe,

Thanks for your feedback.

On 2022-08-29 23:06:43 -0400, Joe Perches wrote:
> > + if ($line =~
> > /(fixes:)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {
>
> Maybe use fixes:? so the colon is not required in poorly formed uses

I tried that but I think it brings more problems then it is worth. With
that change the check would run for each line of the commit message that
begins with the string 'fixes', not just in the tags section of the
message. So it would warn for the commit message,

The work on foo and bar introduced a bug that can be
fixed by doing baz.

I think it's for this reason other checks for tags include the ':'.

>
> > + my $tag = $1;
> > + $orig_commit = $2;
> > + $title = $3;
> > +
> > + $tag_case = 0 if $tag eq "Fixes:";
> > + $tag_space = 0 if ($line =~ /^fixes: [0-9a-f]{5,} ($balanced_parens)/i);
>
> fixes:? here too
>
> Pity there's no simple way to consolidate this git commit test block
> with the existing git id commit block.

I agree.

--
Kind Regards,
Niklas S?derlund

2022-09-05 18:37:16

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: warn for non-standard fixes tag style

On Mon, 2022-09-05 at 12:49 +0200, Niklas S?derlund wrote:
> Hi Joe,
>
> Thanks for your feedback.
>
> On 2022-08-29 23:06:43 -0400, Joe Perches wrote:
> > > + if ($line =~
> > > /(fixes:)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {
> >
> > Maybe use fixes:? so the colon is not required in poorly formed uses
>
> I tried that but I think it brings more problems then it is worth. With
> that change the check would run for each line of the commit message that
> begins with the string 'fixes', not just in the tags section of the
> message. So it would warn for the commit message,

I think it's not a problem.
Look at the results of:

$ git log -100000 --no-merges --format=email --grep="^fixes" -i | \
grep -i -P -oh '^fixes:?\s*[0-9a-f]{5,}\s*..' | \
sed -r -e 's/^(fixes:?\s*)[0-9a-f]+/\1/i' | \
sort | uniq -c | sort -rn | head -20
73974 Fixes: ("
1345 Fixes: ('
399 Fixes:
246 Fixes: (A
215 Fixes: ("
172 Fixes: (c
121 Fixes: (s
114 Fixes: (d
110 Fixes: (P
98 Fixes: (i
90 Fixes: (m
86 Fixes: (n
78 Fixes: :
57 Fixes ("
51 Fixes: "n
47 Fixes: (a
46 Fixes: (t
43 fixes: ("
42 Fixes: (p
41 Fixes: ('


2022-09-06 09:45:23

by Niklas Söderlund

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: warn for non-standard fixes tag style

Hello Joe,

On 2022-09-05 11:00:35 -0700, Joe Perches wrote:
> On Mon, 2022-09-05 at 12:49 +0200, Niklas S?derlund wrote:
> > Hi Joe,
> >
> > Thanks for your feedback.
> >
> > On 2022-08-29 23:06:43 -0400, Joe Perches wrote:
> > > > + if ($line =~
> > > > /(fixes:)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) {
> > >
> > > Maybe use fixes:? so the colon is not required in poorly formed uses
> >
> > I tried that but I think it brings more problems then it is worth. With
> > that change the check would run for each line of the commit message that
> > begins with the string 'fixes', not just in the tags section of the
> > message. So it would warn for the commit message,
>
> I think it's not a problem.
> Look at the results of:
>
> $ git log -100000 --no-merges --format=email --grep="^fixes" -i | \
> grep -i -P -oh '^fixes:?\s*[0-9a-f]{5,}\s*..' | \
> sed -r -e 's/^(fixes:?\s*)[0-9a-f]+/\1/i' | \
> sort | uniq -c | sort -rn | head -20
> 73974 Fixes: ("
> 1345 Fixes: ('
> 399 Fixes:
> 246 Fixes: (A
> 215 Fixes: ("
> 172 Fixes: (c
> 121 Fixes: (s
> 114 Fixes: (d
> 110 Fixes: (P
> 98 Fixes: (i
> 90 Fixes: (m
> 86 Fixes: (n
> 78 Fixes: :
> 57 Fixes ("
> 51 Fixes: "n
> 47 Fixes: (a
> 46 Fixes: (t
> 43 fixes: ("
> 42 Fixes: (p
> 41 Fixes: ('

Thanks for checking this. With this background I agree with you, there
is no problem here. I will spin a v3 with your suggestion.
>

--
Kind Regards,
Niklas S?derlund