Do not require the presence of `$balanced_parens` to get the commit SHA; this allows a `Fixes: deadbeef` tag to get a correct suggestion rather than a suggestion containing a reference to HEAD. Given this patch: : From: Tamir Duberstein <tamird@gmail.com> : Subject: Test patch : Date: Fri, 25 Oct 2024 19:30:51 -0400 : : This is a test patch. : : Fixes: bd17e036b495 : Signed-off-by: Tamir Duberstein <tamird@gmail.com> : --- /dev/null : +++ b/new-file : @@ -0,0 +1 @@ : +Test. Before: WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: c10a7d25e68f ("Test patch")' After: WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: bd17e036b495 ("checkpatch: warn for non-standard fixes tag style")' The prior behavior incorrectly suggested the patch's own SHA and title line rather than the referenced commit's. This fixes that. Ironically this:
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -3209,36 +3209,31 @@ sub process { · 3208 unmodified lines | |||
| 3209 | 3209 | ||
| 3210 | # Check Fixes: styles is correct | 3210 | # Check Fixes: styles is correct |
| 3211 | if (!$in_header_lines && | 3211 | if (!$in_header_lines && |
| 3212 | $line =~ /^\s*fixes:?\s*(?:commit\s*)?[0-9a-f]{5,}\b/i) { | 3212 | $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})(?:\s*($balanced_parens))?/i) { |
| 3213 | my $orig_commit = ""; | 3213 | my $tag = $1; |
| 3214 | my $id = "0123456789ab"; | 3214 | my $orig_commit = $2; |
| 3215 | my $title = "commit title"; | 3215 | my $title; |
| 3216 | my $tag_case = 1; | ||
| 3217 | my $tag_space = 1; | ||
| 3218 | my $id_length = 1; | ||
| 3219 | my $id_case = 1; | ||
| 3220 | my $title_has_quotes = 0; | 3216 | my $title_has_quotes = 0; |
| 3221 | $fixes_tag = 1; | 3217 | $fixes_tag = 1; |
| 3222 | 3218 | if (defined $3) { | |
| 3223 | if ($line =~ /(\s*fixes:?)\s+([0-9a-f]{5,})\s+($balanced_parens)/i) { | ||
| 3224 | my $tag = $1; | ||
| 3225 | $orig_commit = $2; | ||
| 3226 | $title = $3; | ||
| 3227 | |||
| 3228 | $tag_case = 0 if $tag eq "Fixes:"; | ||
| 3229 | $tag_space = 0 if ($line =~ /^fixes:? [0-9a-f]{5,} ($balanced_parens)/i); | ||
| 3230 | |||
| 3231 | $id_length = 0 if ($orig_commit =~ /^[0-9a-f]{12}$/i); | ||
| 3232 | $id_case = 0 if ($orig_commit !~ /[A-F]/); | ||
| 3233 | |||
| 3234 | # Always strip leading/trailing parens then double quotes if existing | 3219 | # Always strip leading/trailing parens then double quotes if existing |
| 3235 | $title = substr($title, 1, -1); | 3220 | $title = substr($3, 1, -1); |
| 3236 | if ($title =~ /^".*"$/) { | 3221 | if ($title =~ /^".*"$/) { |
| 3237 | $title = substr($title, 1, -1); | 3222 | $title = substr($title, 1, -1); |
| 3238 | $title_has_quotes = 1; | 3223 | $title_has_quotes = 1; |
| 3239 | } | 3224 | } |
| 3225 | } else { | ||
| 3226 | $title = "commit title" | ||
| 3240 | } | 3227 | } |
| 3241 | 3228 | ||
| 3229 | |||
| 3230 | my $tag_case = not ($tag eq "Fixes:"); | ||
| 3231 | my $tag_space = not ($line =~ /^fixes:? [0-9a-f]{5,40} ($balanced_parens)/i); | ||
| 3232 | |||
| 3233 | my $id_length = not ($orig_commit =~ /^[0-9a-f]{12}$/i); | ||
| 3234 | my $id_case = not ($orig_commit !~ /[A-F]/); | ||
| 3235 | |||
| 3236 | my $id = "0123456789ab"; | ||
| 3242 | my ($cid, $ctitle) = git_commit_info($orig_commit, $id, | 3237 | my ($cid, $ctitle) = git_commit_info($orig_commit, $id, |
| 3243 | $title); | 3238 | $title); |
| 3244 | 3239 | ||