Re: [PATCH] checkpatch.pl: show how to read from stdin

Previous thread: [PATCH 1/1] PCI: change procfs interface to use unlocked_ioctl instead of ioctl by Sergio Luis on Thursday, January 10, 2008 - 8:26 pm. (2 messages)

Next thread: none
From: Daniel Walker
Date: Thursday, January 10, 2008 - 9:11 pm

A little feature addition to allow checkpatch.pl to check patches piped
into it, in addition to specific file arguments.

Signed-off-by: Daniel Walker <dwalker@mvista.com>
---
 scripts/checkpatch.pl |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Index: linux-2.6.23/scripts/checkpatch.pl
===================================================================
--- linux-2.6.23.orig/scripts/checkpatch.pl
+++ linux-2.6.23/scripts/checkpatch.pl
@@ -24,6 +24,7 @@ my $file = 0;
 my $check = 0;
 my $summary = 1;
 my $mailback = 0;
+my $piped = (-t STDIN) ? 0 : 1;
 my $root;
 GetOptions(
 	'q|quiet+'	=> \$quiet,
@@ -43,7 +44,7 @@ GetOptions(
 
 my $exit = 0;
 
-if ($#ARGV < 0) {
+if ($#ARGV < 0 && !$piped) {
 	print "usage: $P [options] patchfile\n";
 	print "version: $V\n";
 	print "options: -q           => quiet\n";
@@ -181,6 +182,18 @@ if ($tree && -f "$root/$removal") {
 }
 
 my @rawlines = ();
+
+if ($piped) {
+	while (<STDIN>) {
+		chomp;
+		push(@rawlines, $_);
+	}
+	if (!process("", @rawlines)) {
+		$exit = 1;
+	}
+	@rawlines = ();
+}
+
 for my $filename (@ARGV) {
 	if ($file) {
 		open(FILE, "diff -u /dev/null $filename|") ||
-- 

-- 
--

From: Jiri Slaby
Date: Friday, January 11, 2008 - 1:52 am

You can still add - as an argument to check stdin. In which way is this better?

regards,
-- 
Jiri Slaby
Faculty of Informatics, Masaryk University
Suse Labs
--

From: Daniel Walker
Date: Friday, January 11, 2008 - 2:17 am

There's was no reason to limit the arguments ..

I was using it to do something like the following ,

git show 9914cad54c79d0b89b1f066c0894f00e1344131c | ./scripts/checkpatch.pl

Which I think is useful .

Dainel

--

From: Jiri Slaby
Date: Friday, January 11, 2008 - 2:21 am

Ok, and if you add a - there, it should have the same effect, but for free, 
doesn't it:
git show 9914cad54c79d0b89b1f066c0894f00e1344131c | ./scripts/checkpatch.pl -

regards,
-- 
Jiri Slaby
Faculty of Informatics, Masaryk University
Suse Labs
--

From: Daniel Walker
Date: Friday, January 11, 2008 - 2:30 am

Not a particularly attractive command line .. Might still be a good idea
to add this since these two forms alluded me, and are likely to allude
people new to unix all together (who is more likely to be using this
particular tool)..

Daniel

--

From: Jiri Slaby
Date: Friday, January 11, 2008 - 2:34 am

If somebody is hacking kernel, I think he should know the - trick used in many 
programs, but do not consider this as a nack.

thanks,
-- 
Jiri Slaby
Faculty of Informatics, Masaryk University
Suse Labs
--

From: Daniel Walker
Date: Friday, January 11, 2008 - 2:36 am

I'm hacking the kernel, and I didn't know the - trick .. So you have
your testing case all in one with the patch submitter ..

Daniel

--

From: Jiri Slaby
Date: Friday, January 11, 2008 - 2:41 am

OK, maybe we should base it in doc for patch submitting then?

regards,
-- 
Jiri Slaby
Faculty of Informatics, Masaryk University
Suse Labs
--

From: Daniel Walker
Date: Friday, January 11, 2008 - 2:47 am

It's in the bash docs I'm sure, it's just a matter of who ends up
reading that part of the docs.. I still think my patch is a good one ,
we could change the name to "Allow piping with out tricks" I suppose ..

Daniel

--

From: Bernd Petrovitsch
Date: Friday, January 11, 2008 - 3:11 am

Yes, too. And "awk" also supports that.
But "/dev/stdin" is also since ages a symlink to

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


--

From: Stefan Richter
Date: Friday, January 11, 2008 - 4:16 am

How about

 if ($#ARGV < 0) {
 	print "usage: $P [options] patchfile\n";
 	print "version: $V\n";
 	print "options: -q           => quiet\n";
 	print "         --no-tree    => run without a kernel tree\n";
 	print "         --terse      => one line per report\n";
 	print "         --emacs      => emacs compile window format\n";
 	print "         --file       => check a source file\n";
 	print "         --strict     => enable more subjective tests\n";
 	print "         --root       => path to the kernel tree root\n";
+	print "When patchfile is -, read standard input.\n";
 	exit(1);
 }

-- 
Stefan Richter
-=====-==--- ---= -=-==
http://arcgraph.de/sr/
--

From: Jiri Slaby
Date: Friday, January 11, 2008 - 4:50 am

My ACK.

regards,
-- 
Jiri Slaby
Faculty of Informatics, Masaryk University
Suse Labs
--

From: Stefan Richter
Date: Friday, January 11, 2008 - 10:06 am

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
---
 scripts/checkpatch.pl |    1 +
 1 file changed, 1 insertion(+)

Index: linux/scripts/checkpatch.pl
===================================================================
--- linux.orig/scripts/checkpatch.pl
+++ linux/scripts/checkpatch.pl
@@ -53,6 +53,7 @@ if ($#ARGV < 0) {
 	print "         --file       => check a source file\n";
 	print "         --strict     => enable more subjective tests\n";
 	print "         --root       => path to the kernel tree root\n";
+	print "When patchfile is -, read standard input.\n";
 	exit(1);
 }
 

-- 
Stefan Richter
-=====-==--- ---= -=-==
http://arcgraph.de/sr/

--

From: Stefan Richter
Date: Friday, January 11, 2008 - 10:29 am

Why add code for a feature which already exists?
-- 
Stefan Richter
-=====-==--- ---= -=-==
http://arcgraph.de/sr/
--

From: Daniel Walker
Date: Friday, January 11, 2008 - 10:39 am

To make it simpler to use .. A good percentage (if not all) command line
unix data processing utils accept piped data directly, without the need
for the "-" .. That's the expect usage .. checkpatch.pl doesn't need to
deviate from the norm, there is no size constraint, there is no line
limit .. So we're not duplicating functionality, we're making the tool
conform ..

Daniel

--

From: Andy Whitcroft
Date: Monday, January 14, 2008 - 10:17 am

As an absolute minimum this seems reasonable to me.  I guess we could
make no arguments default to '-' also.  There are up and downsides to
doing that, as currently no arguments currently tell you the usage and
with this patch would point clearly out the '-' option.  Just assuming
stding would lose easy access to usage, which may actually be more
confusing for the beginner.  Hmmm.  Cirtainly will include this

-apw
--

From: Daniel Walker
Date: Monday, January 14, 2008 - 10:35 am

The patch that I submitted checks STDIN for piped data, and if there is
any it will default to checking that incoming data .. That's regardless
of the number of arguments given .. 

Daniel

--

From: Andy Whitcroft
Date: Monday, January 14, 2008 - 12:12 pm

So it does, however that of itself differs from the unix norm; as with
this I cannot run checkpatch and "type" (ie paste) a patch fragment to
check it.  So I don't think we want the semantics as you have there,
as its confusing to the experienced user and inconsistent with the norm.
Either we should document the standard '-' usage as has been suggested
elsewhere or always assume stdin with no parameters.

-apw
--

From: Daniel Walker
Date: Monday, January 14, 2008 - 12:17 pm

I'm not sure I understand what you mean .. Can you give an example?

Daniel

--

From: Jiri Slaby
Date: Monday, January 14, 2008 - 12:44 pm

--h (--he --hel --help) suffices due to getopt_long gnu implementation
--

From: Daniel Walker
Date: Monday, January 14, 2008 - 12:51 pm

I tried the following with my changes,

./scripts/checkpatch.pl -
cat | ./scripts/checkpatch.pl

Both allowed pasting patches and pressing Ctrl-D , then it processed the
patch..

and

cat <patchname> | ./scripts/checkpatch.pl

Also processed the patch ..

Daniel

--

From: Bernd Petrovitsch
Date: Friday, January 11, 2008 - 3:08 am

Might be.
But it works for (almost?) all programs (which do not need seekable
input) which absolutely want the input file specified by a parameter.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


--

Previous thread: [PATCH 1/1] PCI: change procfs interface to use unlocked_ioctl instead of ioctl by Sergio Luis on Thursday, January 10, 2008 - 8:26 pm. (2 messages)

Next thread: none