2020-04-29 16:51:50

by Wang YanQing

[permalink] [raw]
Subject: [PATCH] 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]>

Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Wang YanQing <[email protected]>
---
scripts/checkpatch.pl | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23a001a..879dcf4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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);
}
}

--
1.8.5.6.2.g3d8a54e.dirty


2020-04-29 17:42:21

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: add support to check 'Fixes:' tag format

> “...
> 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.
…”



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


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

2020-04-30 12:58:54

by Wang YanQing

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: add support to check 'Fixes:' tag format

On Wed, Apr 29, 2020 at 07:40:21PM +0200, Markus Elfring wrote:
> > “...
> > 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.
> …”
>
>

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

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

>
>
> > + "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\")
...”

>
> Regards,
> Markus

Thanks.

2020-04-30 14:08:58

by Markus Elfring

[permalink] [raw]
Subject: Re: checkpatch: Support for alternative quotation characters around commit title?

> 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

2020-04-30 15:43:17

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] checkpatch: add support to check 'Fixes:' tag format

On Thu, 2020-04-30 at 20:56 +0800, Wang YanQing wrote:
> On Wed, Apr 29, 2020 at 07:40:21PM +0200, Markus Elfring wrote:
> > > “...
> > > 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.
> > …”
> >
> >
>
> 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