Skip to contentSkip to conversation

checkpatch: add support to check 'Fixes:' tag format

PATCH Superseded Wang YanQing 3 participants 5 messages Apr 29, 2020 – Apr 30, 2020

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

Based on original patch by Joe Perches <[email protected]>

---
 scripts/checkpatch.pl | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)
scripts/checkpatch.pl +24 -12
index 23a001a..879dcf4 100755
@@ -2818,11 +2818,13 @@ 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;
@@ -2832,19 +2834,28 @@ sub process {
 			my $id = '0123456789ab';
 			my $orig_desc = "commit description";
 			my $description = "";
+			my $acrosslines = 0;
+			my $title = "title line";
 
-			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)";
+			} 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);
 			}
 
-			$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 ($line =~ /\b$prefix\s+[0-9a-f]{12,40}/i);
+			$long = 1 if ($line =~ /\b$prefix\s+[0-9a-f]{41,}/i);
+			$space = 0 if ($line =~ /\b$prefix [0-9a-f]/i);
+			$case = 0 if ($line =~ /\b$prefix_case\s+[0-9a-f]{5,40}[^A-F]/);
+			if ($line =~ /\b$prefix\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
 				$orig_desc = $1;
 				$hasparens = 1;
 			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
@@ -2852,23 +2863,24 @@ sub process {
 				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
 				$orig_desc = $1;
 				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+			} 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;
+				$line =~ /\b$prefix\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
 				$orig_desc = $1;
 				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
 				$orig_desc .= " " . $1;
 				$hasparens = 1;
+				$acrosslines = 1 if ($prefix eq "Fixes:");
 			}
 
 			($id, $description) = git_commit_info($orig_commit,
 							      $id, $orig_desc);
 
 			if (defined($id) &&
-			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens || $acrosslines)) {
 				ERROR("GIT_COMMIT_ID",
-				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
+				      "Please use git commit description style '$prefix <12+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . " $id (\"$description\")'\n" . $herecurr);
 			}
 		}
 
Signature · 1 line
1.8.5.6.2.g3d8a54e.dirty
#1 lore raw
Quoted 5 lines

“...
Do not split the tag across multiple
lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts
...”

Why do you not like the reformatting of the quotation so far (if such change descriptions should cope also with specific Unicode characters)?

“…
Do not split the tag across multiple lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts. …”

Quoted 3 lines

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.

I have got the impression that this wording might need another bit of fine-tuning.

scripts/checkpatch.pl sub process { · line 2883

Quoted 1 line
scripts/checkpatch.pl +1 -0
+				      "Please use git commit description style '$prefix <12+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . " $id (\"$description\")'\n" . $herecurr);

I imagine that the support for different quotation characters can become helpful, can't it?

Regards,
Markus

#2 lore raw
Quoted 6 lines · Markus Elfring
Quoted 5 lines

“...
Do not split the tag across multiple
lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts
...”

Quoted 10 lines

Why do you not like the reformatting of the quotation so far (if such change descriptions should cope also with specific Unicode characters)?

“…
Do not split the tag across multiple lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts. …”

Sigh. I will fix it, but I want to hear from Joe Perches before next patch version.

Quoted 7 lines
Quoted 4 lines

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.

I have got the impression that this wording might need another bit of fine-tuning.

The current wording is enough I think.

Quoted 6 lines

scripts/checkpatch.pl sub process { · line 2883

Quoted 3 lines
scripts/checkpatch.pl +1 -0
+				      "Please use git commit description style '$prefix <12+ chars of sha1> (\"<$title>\")' - ie: '${init_char}" . substr($prefix, 1) . " $id (\"$description\")'\n" . $herecurr);

I imagine that the support for different quotation characters can become helpful, can't it?

No, we don't need to support other quotation character for 'Fixes:' tag at least now. The submitting-patches.rst tells us the pretty format is:
“...
Fixes: %h (\"%s\")
...”

Quoted 3 lines

Regards,
Markus

Thanks.

#3 lore raw

Re: checkpatch: Support for alternative quotation characters around commit title?

Quoted 5 lines

No, we don't need to support other quotation character for 'Fixes:' tag at least now. The submitting-patches.rst tells us the pretty format is:
“...
Fixes: %h (\"%s\")
...”

Can such a data structure still be correctly parsed if the commit title would contain double quotes?

How do you think about to discuss delimiter variations?

Regards,
Markus

maintainer
#4 lore raw
In reply to Wang YanQing
Quoted 18 lines · Wang YanQing
Quoted 6 lines · Markus Elfring
Quoted 5 lines

“...
Do not split the tag across multiple
lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts
...”

Quoted 10 lines

Why do you not like the reformatting of the quotation so far (if such change descriptions should cope also with specific Unicode characters)?

“…
Do not split the tag across multiple lines, tags are exempt from the "wrap at 75 columns" rule in order to simplify parsing scripts. …”

Quoted 2 lines

Sigh. I will fix it, but I want to hear from Joe Perches before next patch version.

Hello YanQing.

Just ignore Markus' replies here, he's well meaning but perhaps overly focused on trying to impose formal, but somewhat antique grammar and word choice uses that aren't particularly important for review.

The most common variant I see here is someone writes

Fixes SHA1 ("Truncated commit description...")

to apparently avoid a long line.

btw:

you can test your patch using checkpatch and --git like:

$ 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

You could filter that either by modifying the patch changing to "GIT_COMMIT_ID_TEST" and changing to types=GIT_COMMIT_ID_TEST just for Fixes or maybe use another grep like grep -B3 -A3 "Fixes:" -i