Skip to contentSkip to conversation

checkpatch: warn for non-standard fixes tag style

PATCH Superseded Niklas Söderlund 3 participants 6 messages Aug 29, 2022 – Sep 6, 2022

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 Documentation/dev-tools/checkpatch.rst |  6 ++++
 scripts/checkpatch.pl                  | 41 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Documentation/dev-tools/checkpatch.rst +6 -0
index b52452bc2963..8164f362a2fc 100644
@@ -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
 ----------------
scripts/checkpatch.pl +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.37.2
maintainer
#1 lore raw
Quoted 38 lines · Niklas Söderlund

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

---
 Documentation/dev-tools/checkpatch.rst |  6 ++++
 scripts/checkpatch.pl                  | 41 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Documentation/dev-tools/checkpatch.rst +6 -0
index b52452bc2963..8164f362a2fc 100644
@@ -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
 ----------------
scripts/checkpatch.pl +2 -0
index 79e759aac543..9b8cdc582fb5 100755
@@ -3140,6 +3140,47 @@ sub process {
 			}
 		}
 
+# Check Fixes: styles is correct
+		if (!$in_header_lines && $line =~ /^fixes:/i) {

scripts/checkpatch.pl sub process { · line 3154

Quoted 10 lines
scripts/checkpatch.pl +10 -0
+			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

scripts/checkpatch.pl sub process { · line 3160

Quoted 6 lines
scripts/checkpatch.pl +6 -0
+				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.

Quoted 26 lines
scripts/checkpatch.pl +23 -0
+
+				$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 lore raw

Hi Joe,

Thanks for your feedback.

Quoted 4 lines · Joe Perches
Quoted 2 lines
(quoted diff) +1 -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

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 ':'.

Quoted 10 lines

scripts/checkpatch.pl sub process { · line 3160

Quoted 7 lines
scripts/checkpatch.pl +6 -0
+				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
Quoted 2 lines

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

I agree.

Signature · 2 lines
Kind Regards,
Niklas Söderlund
maintainer
#3 lore raw
Quoted 10 lines · Niklas Söderlund

Hi Joe,

Thanks for your feedback.

Quoted 4 lines · Joe Perches
Quoted 2 lines
(quoted diff) +1 -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

Quoted 4 lines

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: ('
#4 lore raw

Hello Joe,

Quoted 35 lines · Joe Perches
Quoted 10 lines · Niklas Söderlund

Hi Joe,

Thanks for your feedback.

Quoted 4 lines · Joe Perches
Quoted 2 lines
(quoted diff) +1 -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

Quoted 4 lines

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
Quoted 8 lines
     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.

Quoted 1 line
Signature · 2 lines
Kind Regards,
Niklas Söderlund
#5 lore raw
In reply to Niklas Söderlund

Documentation/dev-tools/checkpatch.rst Commit message · line 620

Quoted 7 lines · Niklas Söderlund
Documentation/dev-tools/checkpatch.rst +6 -0
+  **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.

Signature · 1 line
An old man doll... just what I always wanted! - Clara