mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
	Andy Whitcroft <apw@canonical.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] checkpatch: use patch subject when reading from stdin
Date: Mon, 14 Oct 2019 07:48:42 -0700	[thread overview]
Message-ID: <fa4ce46605a81d660be73361a4fdd30240a6348e.camel@perches.com> (raw)
In-Reply-To: <CAMuHMdWZYOsJv1uQkOFRK2tZO+E8sSHEneUM-p+q5FyAmYZ9Fw@mail.gmail.com>

On Mon, 2019-10-14 at 11:20 +0200, Geert Uytterhoeven wrote:
> Hi Joe,
> 
> On Tue, Oct 8, 2019 at 8:10 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Tue, Oct 8, 2019 at 7:02 PM Joe Perches <joe@perches.com> wrote:
> > > On Tue, 2019-10-08 at 17:28 +0200, Geert Uytterhoeven wrote:
> > > > On Tue, Oct 8, 2019 at 5:20 PM Joe Perches <joe@perches.com> wrote:
> > > > > On Tue, 2019-10-08 at 11:40 +0200, Geert Uytterhoeven wrote:
> > > > > > When reading a patch file from standard input, checkpatch calls it "Your
> > > > > > patch", and reports its state as:
> > > > > > 
> > > > > >     Your patch has style problems, please review.
> > > > > > 
> > > > > > or:
> > > > > > 
> > > > > >     Your patch has no obvious style problems and is ready for submission.
> > > > > > 
> > > > > > Hence when checking multiple patches by piping them to checkpatch, e.g.
> > > > > > when checking patchwork bundles using:
> > > > > > 
> > > > > >     formail -s scripts/checkpatch.pl < bundle-foo.mbox
> > > > > > 
> > > > > > it is difficult to identify which patches need to be reviewed and
> > > > > > improved.
> > > > > > 
> > > > > > Fix this by replacing "Your patch" by the patch subject, if present.
> > > > > []
> > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > > > []
> > > > > > @@ -1047,6 +1047,10 @@ for my $filename (@ARGV) {
> > > > > >       }
> > > > > >       while (<$FILE>) {
> > > > > >               chomp;
> > > > > > +             if ($vname eq 'Your patch') {
> > > > > > +                     my ($subject) = $_ =~ /^Subject:\s*(.*)/;
> > > > > > +                     $vname = '"' . $subject . '"' if $subject;
> > > > > 
> > > > > Hi again Geert.
> > > > > 
> > > > > Just some stylistic nits:
> > > > > 
> > > > > $filename is not quoted so I think adding quotes
> > > > > before and after $subject may not be useful.
> > > > 
> > > > Filename is indeed not quoted, but $git_commits{$filename} is.
> > > 
> > > If I understand your use case, this will only show the last
> > > patch $subject of a bundle?
> > 
> > False.
> > "formail -s scripts/checkpatch.pl < bundle-foo.mbox" splits
> > "bundle-foo.mbox" in separate patches, and invokes
> > "scripts/checkpatch.pl" for each of them.
> > 
> > > Also, it'll show things like "duplicate signature" when multiple
> > > patches are tested in a single bundle.
> > 
> > False, due to the splitting by formail.
> > 
> > > For instance, if I have a git format-patch series in an output
> > > directory and do
> > > 
> > > $ cat <output_dir>/*.patch | ./scripts/checkpatch.pl
> > > 
> > > Bad output happen.
> > 
> > Yeah, because you're concatenating all patches.
> > Currently it works for single patches only.
> > 
> > > Maybe this might be better:
> > > --- a/scripts/checkpatch.pl
> > > +++ b/scripts/checkpatch.pl
> > > @@ -2444,6 +2444,15 @@ sub process {
> > > 
> > >                 my $rawline = $rawlines[$linenr - 1];
> > > 
> > > +# if input from stdin, report the subject lines if they exist
> > > +               if ($filename eq '-' && !$quiet &&
> > > +                   $rawline =~ /^Subject:\s*(.*)/) {
> > > +                       report("stdin", "STDIN", '-' x length($1));
> > > +                       report("stdin", "STDIN", $1);
> > > +                       report("stdin", "STDIN", '-' x length($1));
> > > +                       %signatures = ();       # avoid duplicate signatures
> > > +               }
> > > +
> > >  # check if it's a mode change, rename or start of a patch
> > >                 if (!$in_commit_log &&
> > >                     ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
> > 
> > Perhaps.  Just passing the patchwork bundle to checkpatch, and fixing
> > checkpatch to handle multiple patches in a single file was my first idea.
> > But it looked fragile, with too much state that needs to be reset.
> > I.e. the state is not limited to %signatures.  You also have to reset
> > $author inside process(), and probably a dozen other variables.
> > And make sure that future changes don't forget resetting all newly
> > introduced variables.
> > 
> > Hence I settled for the solution using formail.
> 
> I gave your solution a try.
> It only enables the reset-on-next-patch feature when using stdin.
> Thanks to the printed subject, it's now obvious to which patch a
> message applies to.
> However, the output is significantly different than when passing
> a split patch series.  Can this be improved upon?
> 
> Note that the only reason I'm using stdin is that I use formail to split
> a bundle in individual patches.  Once checkpatch supports bundles (or
> mboxes) containing multiple patches, there's no longer a need for
> using formail, and the reset-on-next-patch feature should be
> enabled unconditionally.

Using your collection of little tools idea,
why not write a trivial script like:

	grep "^Subject:" $1
	checkpatch.pl $1

and use that as the command line for formail
instead of adding unnecessary complexity to
checkpatch?




  reply	other threads:[~2019-10-14 14:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08  9:40 Geert Uytterhoeven
2019-10-08 12:50 ` Joe Perches
2019-10-08 12:59   ` Geert Uytterhoeven
2019-10-08 15:20 ` Joe Perches
2019-10-08 15:28   ` Geert Uytterhoeven
2019-10-08 17:02     ` Joe Perches
2019-10-08 18:10       ` Geert Uytterhoeven
2019-10-08 18:25         ` Joe Perches
2019-10-08 18:39           ` Geert Uytterhoeven
2019-10-08 18:50             ` Joe Perches
2019-10-14  9:20         ` Geert Uytterhoeven
2019-10-14 14:48           ` Joe Perches [this message]
2019-10-15  6:49             ` Geert Uytterhoeven
2019-10-15 15:50               ` Joe Perches
2019-10-15 16:40                 ` Geert Uytterhoeven
2019-10-15 17:24                   ` Joe Perches
2019-10-16  6:57                     ` Geert Uytterhoeven

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=fa4ce46605a81d660be73361a4fdd30240a6348e.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=geert+renesas@glider.be \
    --cc=geert@linux-m68k.org \
    --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®