linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines
@ 2018-08-06  3:58 Andrew Donnellan
  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
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Donnellan @ 2018-08-06  3:58 UTC (permalink / raw)
  To: linux-kernel, apw, joe; +Cc: fbarrat

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC PATCH 2/2] checkpatch: Fix commit ID test when "commit" and hash on different lines
  2018-08-06  3:58 [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines Andrew Donnellan
@ 2018-08-06  3:58 ` Andrew Donnellan
  2018-08-06  5:07 ` [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines Joe Perches
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Donnellan @ 2018-08-06  3:58 UTC (permalink / raw)
  To: linux-kernel, apw, joe; +Cc: fbarrat

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---

RFC because I'm bad at Perl
---
 scripts/checkpatch.pl | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index aca4d758112a..ae7a54287db7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2662,40 +2662,46 @@ sub process {
 			my $id = '0123456789ab';
 			my $orig_desc = "commit description";
 			my $description = "";
+			my $ref_line = $line;
 
-			if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
+			if ($ref_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) {
+			} elsif ($ref_line =~ /\b([0-9a-f]{12,40})\b/i) {
 				$orig_commit = lc($1);
+				if (defined $rawlines[$linenr - 2] &&
+					$rawlines[$linenr - 2] =~ /\bcommit$/) {
+					$ref_line = "commit " . $ref_line;
+				}
 			}
-			$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) {
+			$short = 0 if ($ref_line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
+			$long = 1 if ($ref_line =~ /\bcommit\s+[0-9a-f]{41,}/i);
+			$space = 0 if ($ref_line =~ /\bcommit [0-9a-f]/i);
+			$case = 0 if ($ref_line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+
+			if ($ref_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 &&
+			} elsif ($ref_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 &&
+			} elsif ($ref_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;
+				$ref_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 &&
+			} elsif ($ref_line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
 				 defined $rawlines[$linenr] &&
 				 defined $rawlines[$linenr + 1] &&
 				 $rawlines[$linenr] =~ /^\s*\("[^"]+/ &&
@@ -2708,7 +2714,7 @@ sub process {
 				$rawlines[$linenr + 1] =~ /^\s*([^"]+)"\)/;
 				$orig_desc .= " " . $1;
 				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+			} elsif ($ref_line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
 				 defined $rawlines[$linenr] &&
 				 defined $rawlines[$linenr + 1] &&
 				 $rawlines[$linenr] =~ /^\s*[^"]+$/ &&
@@ -2716,7 +2722,7 @@ sub process {
 				# line 1: 'commit <hash> ("description',
 				# line 2: 'description continued'
 				# line 3: 'description continued")'
-				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
+				$ref_line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
 				$orig_desc = $1;
 				$rawlines[$linenr] =~ /^\s*([^"]+)$/;
 				$orig_desc .= " " . $1;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines
  2018-08-06  3:58 [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines Andrew Donnellan
  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 ` Joe Perches
  2018-08-06  8:37   ` Andrew Donnellan
  1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2018-08-06  5:07 UTC (permalink / raw)
  To: Andrew Donnellan, linux-kernel, apw; +Cc: fbarrat

On Mon, 2018-08-06 at 13:58 +1000, Andrew Donnellan wrote:
> 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.

The multiple line block code can be difficult to read.

My suggestion is to instead write a subroutine to get the
commit description and compare that against the returned
git commit description.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Donnellan @ 2018-08-06  8:37 UTC (permalink / raw)
  To: Joe Perches, linux-kernel, apw; +Cc: fbarrat

On 06/08/18 15:07, Joe Perches wrote:
> The multiple line block code can be difficult to read.

I 100% agree!

> My suggestion is to instead write a subroutine to get the
> commit description and compare that against the returned
> git commit description.

I'll try and do it up more neatly when I've got some spare time over the 
next few days and send a v2.

Thanks,
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-06  8:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06  3:58 [RFC PATCH 1/2] checkpatch: Correctly detect git commit references that span 3 lines Andrew Donnellan
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).