checkpatch: backport UTF-8 fixes and MAINTAINERS check
PATCH v2 1/5 checkpatch: add a --strict check for utf-8 in commit logs
In reply to Stefan HajnocziFrom: Joe Perches <[email protected]>
Some find using utf-8 in commit logs inappropriate.
Some patch commit logs contain unintended utf-8 characters when doing things like copy/pasting compilation output.
Look for the start of any commit log by skipping initial lines that look like email headers and "From: " lines.
Stop looking for utf-8 at the first signature line.
Conflicts:
QEMU does not have CHK(), use WARN() instead.
QEMU WARN() only takes one argument, drop the 'type' value in the first argument.
--- scripts/checkpatch.pl | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +26 -4
@@ -224,9 +224,8 @@ our $NonptrType; our $Type; our $Declare; -our $UTF8 = qr { - [\x09\x0A\x0D\x20-\x7E] # ASCII - | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte +our $NON_ASCII_UTF8 = qr{ + [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
@@ -235,6 +234,11 @@ our $UTF8 = qr { | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 }x; +our $UTF8 = qr{ + [\x09\x0A\x0D\x20-\x7E] # ASCII + | $NON_ASCII_UTF8 +}x; + # There are still some false positives, but this catches most # common cases. our $typeTypedefs = qr{(?x:
@@ -1179,6 +1183,9 @@ sub process { my $signoff = 0; my $is_patch = 0; + my $in_header_lines = 1; + my $in_commit_log = 0; #Scanning lines before patch + our @report = (); our $cnt_lines = 0; our $cnt_error = 0;
@@ -1331,7 +1338,6 @@ sub process { if ($line =~ /^diff --git.*?(\S+)$/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@; - } elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@;
@@ -1370,6 +1376,8 @@ sub process { if ($line =~ /^\s*signed-off-by:/i) { # This is a signoff, if ugly, so do not double report. $signoff++; + $in_commit_log = 0; + if (!($line =~ /^\s*Signed-off-by:/)) { ERROR("The correct form is \"Signed-off-by\"\n" . $herecurr);
@@ -1398,6 +1406,20 @@ sub process { ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); } +# Check if it's the start of a commit log +# (not a header line and we haven't seen the patch filename) + if ($in_header_lines && $realfile =~ /^$/ && + $rawline !~ /^(commit\b|from\b|\w+:).+$/i) { + $in_header_lines = 0; + $in_commit_log = 1; + } + +# Still not yet in a patch, check for any UTF-8 + if ($in_commit_log && $realfile =~ /^$/ && + $rawline =~ /$NON_ASCII_UTF8/) { + WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr); + } + # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =~ /^-/);
Signature · 1 line
2.14.3
v2 cover checkpatch: backport UTF-8 fixes and MAINTAINERS check
v2:
* Resolve missing CHK() [Thomas]
* Drop first argument to WARN() to match QEMU function arguments
This series cherry picks checkpatch UTF-8 fixes and the MAINTAINERS file check from Linux. Thomas Huth original did the backport in January 2017 but the series was forgotten (<[email protected]>). I did the cherry pick again from scratch.
The MAINTAINERS file check prints a warning when new files are added without a modification to ./MAINTAINERS. It is easy to forget to update ./MAINTAINERS and this check should help us stay on top of new source files.
Joe Perches (4):
checkpatch: add a --strict check for utf-8 in commit logs
checkpatch: ignore email headers better
checkpatch: emit a warning on file add/move/delete
checkpatch: reduce MAINTAINERS update message frequency
Pasi Savanainen (1):
checkpatch: check utf-8 content from a commit log when it's missing
from charset
scripts/checkpatch.pl | 56 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.3
PATCH v2 2/5 checkpatch: check utf-8 content from a commit log when it's missing from charset
From: Pasi Savanainen <[email protected]>
Check that a commit log doesn't contain UTF-8 when a mail header explicitly defines a different charset, like
'Content-Type: text/plain; charset="us-ascii"'
--- scripts/checkpatch.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +11 -2
@@ -1186,6 +1186,8 @@ sub process { my $in_header_lines = 1; my $in_commit_log = 0; #Scanning lines before patch + my $non_utf8_charset = 0; + our @report = (); our $cnt_lines = 0; our $cnt_error = 0;
@@ -1414,8 +1416,15 @@ sub process { $in_commit_log = 1; } -# Still not yet in a patch, check for any UTF-8 - if ($in_commit_log && $realfile =~ /^$/ && +# Check if there is UTF-8 in a commit log when a mail header has explicitly +# declined it, i.e defined some charset where it is missing. + if ($in_header_lines && + $rawline =~ /^Content-Type:.+charset="(.+)".*$/ && + $1 !~ /utf-8/i) { + $non_utf8_charset = 1; + } + + if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ && $rawline =~ /$NON_ASCII_UTF8/) { WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr); }
Signature · 1 line
2.14.3
PATCH v2 3/5 checkpatch: ignore email headers better
In reply to Stefan HajnocziFrom: Joe Perches <[email protected]>
There are some patches created by git format-patch that when scanned by checkpatch report errors on lines like
To: address.tld
This is a checkpatch false positive.
Improve the logic a bit to ignore folded email headers to avoid emitting these messages.
--- scripts/checkpatch.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
@@ -1183,7 +1183,7 @@ sub process { my $signoff = 0; my $is_patch = 0; - my $in_header_lines = 1; + my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch my $non_utf8_charset = 0;
@@ -1411,7 +1411,8 @@ sub process { # Check if it's the start of a commit log # (not a header line and we haven't seen the patch filename) if ($in_header_lines && $realfile =~ /^$/ && - $rawline !~ /^(commit\b|from\b|\w+:).+$/i) { + !($rawline =~ /^\s+\S/ || + $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) { $in_header_lines = 0; $in_commit_log = 1; }
Signature · 1 line
2.14.3
PATCH v2 4/5 checkpatch: emit a warning on file add/move/delete
In reply to Stefan HajnocziFrom: Joe Perches <[email protected]>
Whenever files are added, moved, or deleted, the MAINTAINERS file patterns can be out of sync or outdated.
To try to keep MAINTAINERS more up-to-date, add a one-time warning whenever a patch does any of those.
Conflicts:
QEMU WARN() only takes one argument, drop the 'type' value in the first argument.
--- scripts/checkpatch.pl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +11 -1
@@ -1185,7 +1185,7 @@ sub process { my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch - + my $reported_maintainer_file = 0; my $non_utf8_charset = 0; our @report = ();
@@ -1390,6 +1390,16 @@ sub process { } } +# Check for added, moved or deleted files + if (!$reported_maintainer_file && !$in_commit_log && + ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || + $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || + ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && + (defined($1) || defined($2))))) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + # Check for wrappage within a valid hunk of the file if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { ERROR("patch seems to be corrupt (line wrapped?)\n" .
Signature · 1 line
2.14.3
PATCH v2 5/5 checkpatch: reduce MAINTAINERS update message frequency
In reply to Stefan HajnocziFrom: Joe Perches <[email protected]>
When files are being added/moved/deleted and a patch contains an update to the MAINTAINERS file, assume it's to update the MAINTAINERS file correctly and do not emit the "does MAINTAINERS need updating?" message.
Reported by many people.
(cherry picked from e0d975b1b439c4fef58fbc306c542c94f48bb849)
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
@@ -1390,6 +1390,12 @@ sub process { } } +# Check if MAINTAINERS is being updated. If so, there's probably no need to +# emit the "does MAINTAINERS need updating?" message on file add/move/delete + if ($line =~ /^\s*MAINTAINERS\s*\|/) { + $reported_maintainer_file = 1; + } + # Check for added, moved or deleted files if (!$reported_maintainer_file && !$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
Signature · 1 line
2.14.3
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2 0/5] checkpatch: backport UTF-8 fixes and MAINTAINERS check
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'19015a6f3e checkpatch: reduce MAINTAINERS update message frequency 7fb20f970d checkpatch: emit a warning on file add/move/delete9303812d85 checkpatch: ignore email headers betterf7cec089ae checkpatch: check utf-8 content from a commit log when it's missing from charset d6a1291e63 checkpatch: add a --strict check for utf-8 in commit logs
=== OUTPUT BEGIN ===
Checking PATCH 1/5: checkpatch: add a --strict check for utf-8 in commit logs...
WARNING: line over 80 characters
#101: FILE: scripts/checkpatch.pl:1420:
+ WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr);
total: 0 errors, 1 warnings, 66 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 2/5: checkpatch: check utf-8 content from a commit log when it's missing from charset... Checking PATCH 3/5: checkpatch: ignore email headers better...
Checking PATCH 4/5: checkpatch: emit a warning on file add/move/delete...
WARNING: line over 80 characters
#46: FILE: scripts/checkpatch.pl:1397:
+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
ERROR: line over 90 characters
#49: FILE: scripts/checkpatch.pl:1400:
+ WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
total: 1 errors, 1 warnings, 24 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 5/5: checkpatch: reduce MAINTAINERS update message frequency... === OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 22 lines · On Mon, Apr 30, 2018 at 05:56:30AM -0700, [email protected] wrote:
=== OUTPUT BEGIN ===
Checking PATCH 1/5: checkpatch: add a --strict check for utf-8 in commit logs...
WARNING: line over 80 characters
#101: FILE:scripts/checkpatch.pl:1420:(quoted diff) +1
-0+ WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr);total: 0 errors, 1 warnings, 66 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH inMAINTAINERS.
Checking PATCH 2/5: checkpatch: check utf-8 content from a commit log when it's missing from charset... Checking PATCH 3/5: checkpatch: ignore email headers better...
Checking PATCH 4/5: checkpatch: emit a warning on file add/move/delete...
WARNING: line over 80 characters
#46: FILE:scripts/checkpatch.pl:1397:(quoted diff) +1
-0+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&ERROR: line over 90 characters
#49: FILE:scripts/checkpatch.pl:1400:(quoted diff) +1
-0+ WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
Quoted 8 lines
total: 1 errors, 1 warnings, 24 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.Checking PATCH 5/5: checkpatch: reduce
MAINTAINERSupdate message frequency... === OUTPUT END ===
If there are no objections I'd like to keep this in sync with upstream, and error messages are exempt from the 80 char limit to aid grepping.
Stefan
Quoted 29 lines · Stefan Hajnoczi
Quoted 28 lines · On Mon, Apr 30, 2018 at 05:56:30AM -0700, [email protected] wrote:
=== OUTPUT BEGIN ===
Checking PATCH 1/5: checkpatch: add a --strict check for utf-8 in commit logs...
WARNING: line over 80 characters
#101: FILE:scripts/checkpatch.pl:1420:(quoted diff) +1
-0+ WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr);total: 0 errors, 1 warnings, 66 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH inMAINTAINERS.
Checking PATCH 2/5: checkpatch: check utf-8 content from a commit log when it's missing from charset... Checking PATCH 3/5: checkpatch: ignore email headers better...
Checking PATCH 4/5: checkpatch: emit a warning on file add/move/delete...
WARNING: line over 80 characters
#46: FILE:scripts/checkpatch.pl:1397:(quoted diff) +1
-0+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&ERROR: line over 90 characters
#49: FILE:scripts/checkpatch.pl:1400:(quoted diff) +1
-0+ WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);total: 1 errors, 1 warnings, 24 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
Quoted 5 lines
Quoted 2 lines
Checking PATCH 5/5: checkpatch: reduce
MAINTAINERSupdate message frequency... === OUTPUT END ===If there are no objections I'd like to keep this in sync with upstream, and error messages are exempt from the 80 char limit to aid grepping.
Yes, please keep it as close as possible to upstream. This will also help to backport future patches from the Linux version to our version (so we can cherry-pick without conflicts).
Thomas
Re: [Qemu-devel] [PATCH v2 1/5] checkpatch: add a --strict check for utf-8 in commit logs
In reply to Stefan HajnocziQuoted 20 lines · Stefan Hajnoczi
From: Joe Perches <[email protected]>
Some find using utf-8 in commit logs inappropriate.
Some patch commit logs contain unintended utf-8 characters when doing things like copy/pasting compilation output.
Look for the start of any commit log by skipping initial lines that look like email headers and "From: " lines.
Stop looking for utf-8 at the first signature line.
Signed-off-by Joe Perches <[email protected]>Suggested-by Andrew Morton <[email protected]>Cc Andy Whitcroft <[email protected]>Signed-off-by Andrew Morton <[email protected]>Signed-off-by Linus Torvalds <[email protected]>(cherry picked from commit 15662b3e8644905032c2e26808401a487d4e90c1)Signed-off-by Stefan Hajnoczi <[email protected]>
Quoted 8 lines
Conflicts:
QEMU does not haveCHK(), useWARN()instead.QEMU
WARN()only takes one argument, drop the 'type' value in the first argument.--- scripts/checkpatch.pl | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
Quoted 4 lines · Stefan Hajnoczi
v2:
* Resolve missingCHK()[Thomas]
* Drop first argument toWARN()to match QEMU function arguments
Quoted 8 lines
This series cherry picks checkpatch UTF-8 fixes and the
MAINTAINERSfile check from Linux. Thomas Huth original did the backport in January 2017 but the series was forgotten (<[email protected]>). I did the cherry pick again from scratch.The
MAINTAINERSfile check prints a warning when new files are added without a modification to ./MAINTAINERS. It is easy to forget to update ./MAINTAINERS and this check should help us stay on top of new source files.
The matching is a bit sloppy in places, but if it's good enough for the kernel...
Series:
Quoted 29 lines · Stefan Hajnoczi
Quoted 28 lines · On Mon, Apr 30, 2018 at 05:56:30AM -0700, [email protected] wrote:
=== OUTPUT BEGIN ===
Checking PATCH 1/5: checkpatch: add a --strict check for utf-8 in commit logs...
WARNING: line over 80 characters
#101: FILE:scripts/checkpatch.pl:1420:(quoted diff) +1
-0+ WARN("8-bit UTF-8 used in possible commit log\n" . $herecurr);total: 0 errors, 1 warnings, 66 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH inMAINTAINERS.
Checking PATCH 2/5: checkpatch: check utf-8 content from a commit log when it's missing from charset... Checking PATCH 3/5: checkpatch: ignore email headers better...
Checking PATCH 4/5: checkpatch: emit a warning on file add/move/delete...
WARNING: line over 80 characters
#46: FILE:scripts/checkpatch.pl:1397:(quoted diff) +1
-0+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&ERROR: line over 90 characters
#49: FILE:scripts/checkpatch.pl:1400:(quoted diff) +1
-0+ WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);total: 1 errors, 1 warnings, 24 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
Quoted 5 lines
Quoted 2 lines
Checking PATCH 5/5: checkpatch: reduce
MAINTAINERSupdate message frequency... === OUTPUT END ===If there are no objections I'd like to keep this in sync with upstream, and error messages are exempt from the 80 char limit to aid grepping.
Yeah, I actually like such exceptions for message strings constants in general.
Fam
Stefan Hajnoczi
AppliedQuoted 19 lines · Stefan Hajnoczi
v2:
* Resolve missingCHK()[Thomas]
* Drop first argument toWARN()to match QEMU function argumentsThis series cherry picks checkpatch UTF-8 fixes and the
MAINTAINERSfile check from Linux. Thomas Huth original did the backport in January 2017 but the series was forgotten (<[email protected]>). I did the cherry pick again from scratch.The
MAINTAINERSfile check prints a warning when new files are added without a modification to ./MAINTAINERS. It is easy to forget to update ./MAINTAINERS and this check should help us stay on top of new source files.Joe Perches (4):
checkpatch: add a --strict check for utf-8 in commit logs
checkpatch: ignore email headers better
checkpatch: emit a warning on file add/move/delete
checkpatch: reduceMAINTAINERSupdate message frequency
Quoted 11 lines
Pasi Savanainen (1):
checkpatch: check utf-8 content from a commit log when it's missing
from charsetscripts/checkpatch.pl | 56 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-)Signature · 1 line
2.14.3
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan