From: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
To: linux-kernel@vger.kernel.org, apw@canonical.com, joe@perches.com
Cc: fbarrat@linux.vnet.ibm.com
Subject: [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines
Date: Mon, 6 Aug 2018 13:58:08 +1000 [thread overview]
Message-ID: <20180806035809.24752-1-andrew.donnellan@au1.ibm.com> (raw)
If a patch contains a commit reference that happens to span 3 lines, e.g.:
===
With the optimizations for TLB invalidation from commit 0cef77c7798a
("powerpc/64s/radix: flush remote CPUs out of single-threaded
mm_cpumask"), the scope of a TLBI (global vs. local) can now be
influenced by the value of the 'copros' counter of the memory context.
===
checkpatch will return a GIT_COMMIT_ID error even though the reference
actually follows the correct format.
Fix the GIT_COMMIT_ID test so it can match against a reference that spans 3
lines.
Reported-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
Sending this as an RFC because I don't actually know how to Perl or regex,
this whole test looks pretty gross and this patch just makes it gross-er,
and it's only lightly tested. Suggestions on how to do this more neatly are
welcome.
We currently have checkpatch running on every incoming patch on
linuxppc-dev, and we've already hit this bug at least twice in the past
couple of weeks.
---
scripts/checkpatch.pl | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 447857ffaf6b..aca4d758112a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2669,27 +2669,60 @@ sub process {
} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
$orig_commit = lc($1);
}
-
$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,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) {
+ # Reference fits on 1 line
$orig_desc = $1;
$hasparens = 1;
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
defined $rawlines[$linenr] &&
$rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
+ # line 1: 'commit <hash>',
+ # line 2: '("description")'
$orig_desc = $1;
$hasparens = 1;
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
defined $rawlines[$linenr] &&
$rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
+ # line 1: 'commit <hash> ("description',
+ # line 2: 'description continued")'
$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
$orig_desc = $1;
$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
$orig_desc .= " " . $1;
$hasparens = 1;
+ } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
+ defined $rawlines[$linenr] &&
+ defined $rawlines[$linenr + 1] &&
+ $rawlines[$linenr] =~ /^\s*\("[^"]+/ &&
+ $rawlines[$linenr + 1] =~ /^\s*[^"]+"\)/) {
+ # line 1: 'commit <hash>',
+ # line 2: '("description'
+ # line 3: 'description continued")'
+ $rawlines[$linenr] =~ /^\s*\("([^"]+)/;
+ $orig_desc = $1;
+ $rawlines[$linenr + 1] =~ /^\s*([^"]+)"\)/;
+ $orig_desc .= " " . $1;
+ $hasparens = 1;
+ } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+ defined $rawlines[$linenr] &&
+ defined $rawlines[$linenr + 1] &&
+ $rawlines[$linenr] =~ /^\s*[^"]+$/ &&
+ $rawlines[$linenr + 1] =~ /^\s*[^"]+"\)/) {
+ # line 1: 'commit <hash> ("description',
+ # line 2: 'description continued'
+ # line 3: 'description continued")'
+ $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
+ $orig_desc = $1;
+ $rawlines[$linenr] =~ /^\s*([^"]+)$/;
+ $orig_desc .= " " . $1;
+ $rawlines[$linenr + 1] =~ /^\s*([^"]+)"\)/;
+ $orig_desc .= " " . $1;
+ $hasparens = 1;
}
($id, $description) = git_commit_info($orig_commit,
--
2.11.0
next reply other threads:[~2018-08-06 3:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-06 3:58 Andrew Donnellan [this message]
2018-08-06 3:58 ` [RFC PATCH 2/2] checkpatch: Fix commit ID test when "commit" and hash on different lines Andrew Donnellan
2018-08-06 5:07 ` [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines Joe Perches
2018-08-06 8:37 ` Andrew Donnellan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180806035809.24752-1-andrew.donnellan@au1.ibm.com \
--to=andrew.donnellan@au1.ibm.com \
--cc=apw@canonical.com \
--cc=fbarrat@linux.vnet.ibm.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®