Skip to contentSkip to conversation

checkpatch: backport UTF-8 fixes and MAINTAINERS check

PATCH Superseded Stefan Hajnoczi 3 participants 12 messages Apr 19, 2018 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#3 lore raw

PATCH 2/5 checkpatch: check utf-8 content from a commit log when it's missing from charset

In reply to Stefan Hajnoczi

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"'

Cc Joe Perches <[email protected]>
Cc Andy Whitcroft <[email protected]>
(cherry picked from commit fa64205df9dfd7b7662cc64a7e82115c00e428e5)
---
 scripts/checkpatch.pl | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +12 -3
index 2d28db03a0..b2b088bab7 100755
@@ -1185,6 +1185,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;
@@ -1413,10 +1415,17 @@ 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/) {
-			CHK("UTF8_BEFORE_PATCH",
+			WARN("UTF8_BEFORE_PATCH",
 			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);
 		}
 
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/5 checkpatch: add a --strict check for utf-8 in commit logs

In reply to 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.

Cc Andy Whitcroft <[email protected]>
(cherry picked from commit 15662b3e8644905032c2e26808401a487d4e90c1)
---
 scripts/checkpatch.pl | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +27 -4
index d52207a3cc..2d28db03a0 100755
@@ -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:
@@ -1178,6 +1182,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;
@@ -1330,7 +1337,6 @@ sub process {
 		if ($line =~ /^diff --git.*?(\S+)$/) {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@;
-
 		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@;
@@ -1369,6 +1375,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);
@@ -1397,6 +1405,21 @@ 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/) {
+			CHK("UTF8_BEFORE_PATCH",
+			    "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
#0 lore raw

cover checkpatch: backport UTF-8 fixes and MAINTAINERS check

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 | 58 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.3
#9 lore raw

PATCH 5/5 checkpatch: reduce MAINTAINERS update message frequency

From: 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
index 95ba64f3a5..1c20c683e8 100755
@@ -1389,6 +1389,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
#7 lore raw

PATCH 4/5 checkpatch: emit a warning on file add/move/delete

In reply to Stefan Hajnoczi

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

(cherry picked from commit 13f1937ef33950b1112049972249e6191b82e6c9)
---
 scripts/checkpatch.pl | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +12 -1
index f3b166d5e2..95ba64f3a5 100755
@@ -1184,7 +1184,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 = ();
@@ -1389,6 +1389,17 @@ 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("FILE_PATH_CHANGES",
+			     "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
#5 lore raw

PATCH 3/5 checkpatch: ignore email headers better

In reply to Stefan Hajnoczi

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

(cherry picked from commit 29ee1b0c67e0dd7dea8dd718e8326076bce5b6fe)
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
index b2b088bab7..f3b166d5e2 100755
@@ -1182,7 +1182,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;
@@ -1410,7 +1410,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
#11 lore raw
In reply to Stefan Hajnoczi
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 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
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
77f2922cd7 checkpatch: reduce MAINTAINERS update message frequency c5660effcb checkpatch: emit a warning on file add/move/delete
4f224ba569 checkpatch: ignore email headers better
8524202abe checkpatch: check utf-8 content from a commit log when it's missing from charset dab42b2f0d 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
#96: FILE: scripts/checkpatch.pl:1420:
+ "8-bit UTF-8 used in possible commit log\n" . $herecurr);

total: 0 errors, 1 warnings, 67 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
#41: FILE: scripts/checkpatch.pl:1396:
+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&

ERROR: line over 90 characters
#45: FILE: scripts/checkpatch.pl:1400:
+ "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);

total: 1 errors, 1 warnings, 25 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]

#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] checkpatch: add a --strict check for utf-8 in commit logs

In reply to Stefan Hajnoczi
Quoted 27 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.

Cc Andy Whitcroft <[email protected]>
(cherry picked from commit 15662b3e8644905032c2e26808401a487d4e90c1)
---
 scripts/checkpatch.pl | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +0 -0
index d52207a3cc..2d28db03a0 100755

[...]

Quoted 8 lines
scripts/checkpatch.pl +4 -0
@@ -1397,6 +1405,21 @@ 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) {

scripts/checkpatch.pl sub process { · line 1421

Quoted 10 lines
scripts/checkpatch.pl +10 -0
+			$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/) {
+			CHK("UTF8_BEFORE_PATCH",
+			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);
+		}

As far as I can see, we don't have that CHK() function in our version of checkpatch.pl yet, so you'd either have to turn that into a WARN or port the CHK() function, too?

Thomas

Reviewed-by on v1 2/5
#4 lore raw

Re: [Qemu-devel] [PATCH 2/5] checkpatch: check utf-8 content from a commit log when it's missing from charset

In reply to Stefan Hajnoczi
Quoted 32 lines · Stefan Hajnoczi

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"'

Cc Joe Perches <[email protected]>
Cc Andy Whitcroft <[email protected]>
(cherry picked from commit fa64205df9dfd7b7662cc64a7e82115c00e428e5)
---
 scripts/checkpatch.pl | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +2 -0
index 2d28db03a0..b2b088bab7 100755
@@ -1185,6 +1185,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;

scripts/checkpatch.pl sub process { · line 1421

Quoted 9 lines
scripts/checkpatch.pl +4 -2
@@ -1413,10 +1415,17 @@ 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="(.+)".*$/ &&

In my version of the patch, I removed the quotes:

https://patchwork.kernel.org/patch/9539231/

... but I guess I should likely follow up on that change with the kernel folks first ...

scripts/checkpatch.pl sub process { · line 1429

Quoted 9 lines
scripts/checkpatch.pl +6 -1
+		    $1 !~ /utf-8/i) {
+			$non_utf8_charset = 1;
+		}
+
+		if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
 		    $rawline =~ /$NON_ASCII_UTF8/) {
-			CHK("UTF8_BEFORE_PATCH",
+			WARN("UTF8_BEFORE_PATCH",
 			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);

Ah, here's the WARN instead of CHK ... in case you respin, you should do that in the first patch already, I think.

In either case:

Reviewed-by on v1 3/5
#6 lore raw

Re: [Qemu-devel] [PATCH 3/5] checkpatch: ignore email headers better

In reply to Stefan Hajnoczi
Quoted 12 lines · Stefan Hajnoczi

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

Quoted 8 lines
(cherry picked from commit 29ee1b0c67e0dd7dea8dd718e8326076bce5b6fe)
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Reviewed-by on v1 4/5
#8 lore raw

Re: [Qemu-devel] [PATCH 4/5] checkpatch: emit a warning on file add/move/delete

In reply to Stefan Hajnoczi
Quoted 14 lines · Stefan Hajnoczi

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

(cherry picked from commit 13f1937ef33950b1112049972249e6191b82e6c9)
Quoted 3 lines
---
 scripts/checkpatch.pl | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
Reviewed-by on v1 5/5
#10 lore raw

Re: [Qemu-devel] [PATCH 5/5] checkpatch: reduce MAINTAINERS update message frequency

In reply to Stefan Hajnoczi
Quoted 25 lines · Stefan Hajnoczi

From: 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 +0 -0
index 95ba64f3a5..1c20c683e8 100755
@@ -1389,6 +1389,12 @@ sub process {
 			}
 		}

scripts/checkpatch.pl sub process { · line 1400

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