checkpatch: add support to check 'Fixes:' tag format
Subsystems (3)
PATCH v5 1/1 checkpatch: add support to check 'Fixes:' tag format
According to submitting-patches.rst, 'Fixes:' tag has a little stricter condition about the one line summary than normal git commit description:
“...
Do not split the tag across multiple lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts ...”
And there is no sanity check for 'Fixes:' tag format in checkpatch the same as GIT_COMMIT_ID for git commit description, so let's expand the GIT_COMMIT_ID to add 'Fixes:' tag format check support.
The check supports below formats:
The check doesn't support below formats and it will emit diagnostics info for them:
Because after GIT_COMMIT_ID supports 'Fixes:' tag format check, it could do the same check as the UNKNOWN_COMMIT_ID, so we don't need UNKNOWN_COMMIT_ID anymore and I decide to delete it.
Note: this patch also fixes double quotation mark issue for normal git
commit description, and now it supports double quotation mark in title line, for example:
Commit e33e2241e272 ("Revert "cfg80211: Use 5MHz bandwidth by default when checking usable channels"")
Note: this patch also adds diagnostics info support for normal git commit
description format check.
Based on original patch by Joe Perches <[email protected]>
---
Hi! Joe and all.
This is the v5 version, and I have tested it with below command:
$ git log -10000 --no-merges --grep="Fixes:" --format=%H | \ while read commit ; do \ ./scripts/checkpatch.pl --git $commit --types=GIT_COMMIT_ID --quiet --nosummary; \ done
The result looks good enough already.
Thanks.
v5:
1: Rebased on '[PATCH v2] checkpatch: fix can't check for too long invalid commit id'. 2: Fix wrong diagnostics info for below non-standard 'Fixes:' formats.
a: Fixes: 03404e8ae652("IB/mlx5: Add support to dropless RQ")
b: Fixes: da97e18458fb: ("perf_event: Add support for LSM and SELinux checks")
3: Reword the diagnostics info for non-standard title format.
v4:
1: Add diagnostics info support, suggested by Joe Perches and Markus Elfring. 2: Delete UNKNOWN_COMMIT_ID and do the check in GIT_COMMIT_ID.
v3:
1: Fix a bug in short title line support.
v2:
1: Add support for double quotation mark in title line, suggested by Markus Elfring. 2: Add support for short title line with/without ellipsis.
3: Add supported format examples and unsupported format examples in changelog. 4: Fix a little wording issue in changelog , suggested by Markus Elfring.
scripts/checkpatch.pl | 120 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 30 deletions(-)
scripts/checkpatch.pl +90 -30
@@ -2818,51 +2818,101 @@ sub process { $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i && $line !~ /^This reverts commit [0-9a-f]{7,40}/ && ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || + $line =~ /\bfixes:\s+[0-9a-f]{5,}\b/i || ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i && - $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i && - $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) { + $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i))) { my $init_char = "c"; my $orig_commit = ""; + my $prefix = "commit"; + my $prefix_case = "[Cc]ommit"; my $short = 1; my $long = 0; my $case = 1; my $space = 1; + my $space2 = 1; my $hasdesc = 0; - my $hasparens = 0; + my $has_parens_and_dqm = 0; # Double quotation mark my $hasprefix = 1; my $id = '0123456789ab'; my $orig_desc = "commit description"; my $description = ""; my $sha1_length_min = 12; + my $acrosslines = 0; + my $title = "title line"; + my $desc_mismatch = 0; + my $diagnostics = "Diagnostics info:\n"; - if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) { + if ($line =~ /\b(f)ixes:\s+([0-9a-f]{5,})\b/i) { + $init_char = $1; + $orig_commit = lc($2); + $prefix = "Fixes:"; + $prefix_case = "Fixes:"; + $init_char = "F"; + $title = "a single line title (without line breaks but ellipsis is fine!)"; + } elsif ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) { $init_char = $1; $orig_commit = lc($2); } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) { $orig_commit = lc($1); $hasprefix = 0; + $diagnostics .= "Missing prefix \"$prefix_case\".\n"; + + } + + if ($line =~ /\b$prefix\s+[0-9a-f]{41,}/i) { + $long = 1; + } elsif ($line =~ /\b$prefix\s+[0-9a-f]{$sha1_length_min,40}/i) { + $short = 0; + } elsif ($hasprefix) { + $diagnostics .= "Commit id $orig_commit is too short.\n"; + } + + if ($line =~ /\b$prefix [0-9a-f]/i) { + $space = 0; + } elsif ($hasprefix) { + $diagnostics .= "Extra whitespace between prefix \"${init_char}" . substr($prefix, 1) . "\" and $orig_commit.\n"; + } + + if ($line =~ /[0-9a-f]{5,} \S+/i || $line =~ /[0-9a-f]{5,}\s*$/i) { + $space2 = 0; + } elsif ($hasprefix) { + $diagnostics .= "We need a single whitespace and only a single whitespace between $orig_commit and title.\n"; } - $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{$sha1_length_min,40}/i); - $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); - $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); - $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); - if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { + if ($line =~ /\b$prefix_case\s+[0-9a-f]{5,40}[^A-F]/) { + $case = 0; + } elsif ($hasprefix) { + $line =~ /(\b$prefix)\s+[0-9a-f]{5,40}[^A-F]/i; + $diagnostics .= "The prefix \"$1\" has case error.\n"; + } + + if ($line =~ /\b$prefix\s+[0-9a-f]{5,}\s+\("(.+)"\)/i) { $orig_desc = $1; - $hasparens = 1; + $has_parens_and_dqm = 1; + # Drop the ellipsis + if ($prefix eq "Fixes:" && $orig_desc =~ /(\s*\.{3}\s*$)/) { + $orig_desc = substr($orig_desc, 0, length($orig_desc) - length($1)); + } } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && defined $rawlines[$linenr] && - $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { + $rawlines[$linenr] =~ /^\s*\("(.+)"\)/) { $orig_desc = $1; - $hasparens = 1; - } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && + $has_parens_and_dqm = 1; + } elsif ($line =~ /\b$prefix\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 =~ /\b$prefix\s+[0-9a-f]{5,}\s+\("(.+)$/i; $orig_desc = $1; - $rawlines[$linenr] =~ /^\s*([^"]+)"\)/; + $rawlines[$linenr] =~ /^\s*(.+)"\)/; $orig_desc .= " " . $1; - $hasparens = 1; + $has_parens_and_dqm = 1; + + if ($prefix eq "Fixes:") { + $acrosslines = 1; + $diagnostics .= "The title acrosses lines.\n"; + } + } elsif ($hasprefix && !$space2) { + $diagnostics .= "No title in '(\"<$title>\")' format is found.\n"; } ($id, $description) = git_commit_info($orig_commit,
@@ -2879,10 +2929,31 @@ sub process { } } + if (defined($id) && $has_parens_and_dqm && ($orig_desc ne $description)) { + # Allow short description without too short! + if ($prefix eq "Fixes:") { + if (length($orig_desc) >= length($description)/2) { + my $desc = substr($description, 0, length($orig_desc)); + + if ($orig_desc ne $desc) { + $desc_mismatch = 1; + $diagnostics .= "The title doesn't match the original commit.\n"; + } + } else { + $desc_mismatch = 1; + $diagnostics .= "The title is too abbreviated, at least half of orignial commit title is necessary.\n"; + } + } else { + $desc_mismatch = 1; + $diagnostics .= "The title doesn't match the original commit.\n"; + } + } + if (defined($id) && - ($short || $space || $case || ($orig_desc ne $description) || !$hasparens)) { + ($short || $space || $space2 || $case || $desc_mismatch || !$hasprefix || !$has_parens_and_dqm || $acrosslines)) { ERROR("GIT_COMMIT_ID", - "Please use git commit description style 'commit <$sha1_length_min+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr); + "Please use git commit description style '$prefix <$sha1_length_min+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . + " $id (\"$description\")'\n" . $diagnostics . $herecurr); } }
@@ -2982,17 +3053,6 @@ sub process { } } -# check for invalid commit id - if ($in_commit_log && $line =~ /^fixes:\s+([0-9a-f]{6,40})\b/i) { - my $id; - my $description; - ($id, $description) = git_commit_info($1, undef, undef); - if (!defined($id)) { - WARN("UNKNOWN_COMMIT_ID", - "Unknown commit id '$1', maybe rebased or not pulled?\n" . $herecurr); - } - } - # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =~ /^-/);
Signature · 1 line
1.8.5.6.2.g3d8a54e.dirty
Quoted 1 line
“...
Can the character “Horizontal ellipsis” (U+2026) be occasionally nicer instead of three separate dots?
Quoted 1 line
The check supports below formats:
I would prefer the explicit wording for the support of (Unicode) ellipses also in the shown commit titles.
Will the document “submitting-patches.rst” need corresponding adjustments?
Quoted 3 lines
Because after
GIT_COMMIT_IDsupports 'Fixes:' tag format check, it could do the same check as theUNKNOWN_COMMIT_ID, so we don't needUNKNOWN_COMMIT_IDanymore and I decide to delete it.
Would you like to propose related software adjustments?
Quoted 5 lines
Note: this patch also fixes double quotation mark issue for normal git
commit description, and now it supports double quotation mark in title line, for example:
Commite33e2241e272("Revert "cfg80211: Use 5MHz bandwidth by default when checking usable channels"")
Do you care to achieve a safer data format description also for this use case?
Quoted 1 line
This is the v5 version, and I have tested it with below command:
How do you think about to reuse the analysis approach outside the script “checkpatch.pl”?
Quoted 2 lines
v5:
1: Rebased on '[PATCH v2] checkpatch: fix can't check for too long invalid commit id'.
Are the software dependencies (and corresponding development challenges) growing?
…
Quoted 2 lines
+++
b/scripts/checkpatch.pl(quoted diff) +0
-0@@ -2818,51 +2818,101 @@ sub process {
…
scripts/checkpatch.pl sub process { · line 2821
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $line =~ /\bfixes:\s+[0-9a-f]{5,}\b/i ||
Would you like to reconsider the program organisation according to the application of regular expressions?
…
scripts/checkpatch.pl sub process { · line 2933
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ if (defined($id) && $has_parens_and_dqm && ($orig_desc ne $description)) { + # Allow short description without too short!
Will another wording adjustment become relevant here?
scripts/checkpatch.pl sub process { · line 2935
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ if ($prefix eq "Fixes:") { + if (length($orig_desc) >= length($description)/2) {
Will the structure of the commit title matter any more?
…
scripts/checkpatch.pl sub process { · line 2944
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $diagnostics .= "The title is too abbreviated, at least half of orignial commit title is necessary.\n";
Will the word “original” be more appropriate here? (Why did you not integrate my previous patch review comment?)
…
scripts/checkpatch.pl sub process { · line 2956
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ "Please use git commit description style '$prefix <$sha1_length_min+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . + " $id (\"$description\")'\n" . $diagnostics . $herecurr);
Can error diagnostics become multi-line?
Regards,
Markus
Quoted 7 lines · Markus Elfring
…
scripts/checkpatch.pl sub process { · line 2944
Quoted 1 line
scripts/checkpatch.pl +1
-0+ $diagnostics .= "The title is too abbreviated, at least half of orignial commit title is necessary.\n";Will the word “original” be more appropriate here? (Why did you not integrate my previous patch review comment?)
Sorry, I miss it.
This version patch has indentation issue, I will fix the typo with the indentation issue in next version (v6).
Thanks.
Quoted 7 lines
…
scripts/checkpatch.pl sub process { · line 2956
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ "Please use git commit description style '$prefix <$sha1_length_min+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . + " $id (\"$description\")'\n" . $diagnostics . $herecurr);Can error diagnostics become multi-line?
The length of "$description" is unknown, it is difficult to cook the error message into pretty format with any length of "$description", so let's keep it in current way.
Thanks.
Quoted 7 lines
Quoted 4 lines
scripts/checkpatch.pl sub process { · line 2956
Quoted 2 lines
scripts/checkpatch.pl +2
-0+ "Please use git commit description style '$prefix <$sha1_length_min+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . + " $id (\"$description\")'\n" . $diagnostics . $herecurr);Can error diagnostics become multi-line?
The length of "$description" is unknown, it is difficult to cook the error message into pretty format with any length of "$description", so let's keep it in current way.
How do you think about a message variant like the following?
+ "Please use git commit description style:\n$prefix <$sha1_length_min+ chars of sha1> (\"<$title>\")\n" . substr($prefix, 1)
+ . "i. e.: '${init_char} $id (\"$description\")\n"
+ . $diagnostics . $herecurr);Regards,
Markus