2009-12-23 13:55:38

by Borislav Petkov

[permalink] [raw]
Subject: [PATCH] scripts/get_maintainer.pl: add support for STDIN:

Teach get_maintainer.pl to read a diff from STDIN so that you can do
something like:

git diff | ./scripts/get_maintainer.pl -

and have the Cc: list before writing the commit message.

Cc: Joe Perches <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
---
scripts/get_maintainer.pl | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 445e884..80d5a69 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -5,7 +5,7 @@
# Print selected MAINTAINERS information for
# the files modified in a patch or for a file
#
-# usage: perl scripts/get_maintainer.pl [OPTIONS] <patch>
+# usage: perl scripts/get_maintainer.pl [OPTIONS] <patch>|STDIN
# perl scripts/get_maintainer.pl [OPTIONS] -f <file>
#
# Licensed under the terms of the GNU GPL License version 2
@@ -237,7 +237,7 @@ foreach my $file (@ARGV) {
##if $file is a directory and it lacks a trailing slash, add one
if ((-d $file)) {
$file =~ s@([^/])$@$1/@;
- } elsif (!(-f $file)) {
+ } elsif (!(-f $file) && ($file ne '-')) {
die "$P: file '${file}' not found\n";
}
if ($from_filename) {
@@ -255,7 +255,11 @@ foreach my $file (@ARGV) {
} else {
my $file_cnt = @files;
my $lastfile;
- open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
+ if ($file eq '-') {
+ open(PATCH, "<&STDIN");
+ } else {
+ open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
+ }
while (<PATCH>) {
my $patch_line = $_;
if (m/^\+\+\+\s+(\S+)/) {
@@ -422,7 +426,7 @@ sub file_match_pattern {

sub usage {
print <<EOT;
-usage: $P [options] patchfile
+usage: $P [options] patchfile|-
$P [options] -f file|directory
version: $V

--
1.6.5.4


--
Regards/Gruss,
Boris


2009-12-23 23:27:10

by Joe Perches

[permalink] [raw]
Subject: [PATCH] scripts/get_maintainer.pl: add support to read patch from STDIN

On Wed, 2009-12-23 at 14:55 +0100, Borislav Petkov wrote:
> Teach get_maintainer.pl to read a diff from STDIN

How about this instead?

Doesn't need or accept '-' as a trailing option to read stdin.
Doesn't print usage() after bad options.
Adds --usage as command line equivalent of --help

Signed-off-by: Joe Perches <[email protected]>

scripts/get_maintainer.pl | 110 ++++++++++++++++++++++++++++-----------------
1 files changed, 69 insertions(+), 41 deletions(-)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 445e884..9fe4628 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -122,7 +122,7 @@ if (!GetOptions(
'k|keywords!' => \$keywords,
'f|file' => \$from_filename,
'v|version' => \$version,
- 'h|help' => \$help,
+ 'h|help|usage' => \$help,
)) {
die "$P: invalid argument - use --help if necessary\n";
}
@@ -137,9 +137,9 @@ if ($version != 0) {
exit 0;
}

-if ($#ARGV < 0) {
- usage();
- die "$P: argument missing: patchfile or -f file please\n";
+if (-t STDIN && !@ARGV) {
+ # We're talking to a terminal, but have no command line arguments.
+ die "$P: missing patchfile or -f file - use --help if necessary\n";
}

if ($output_separator ne ", ") {
@@ -152,14 +152,12 @@ if ($output_rolestats) {

my $selections = $email + $scm + $status + $subsystem + $web;
if ($selections == 0) {
- usage();
die "$P: Missing required option: email, scm, status, subsystem or web\n";
}

if ($email &&
($email_maintainer + $email_list + $email_subscriber_list +
$email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
- usage();
die "$P: Please select at least 1 email option\n";
}

@@ -233,12 +231,18 @@ my @files = ();
my @range = ();
my @keyword_tvi = ();

+if (!@ARGV) {
+ push(@ARGV, "&STDIN");
+}
+
foreach my $file (@ARGV) {
- ##if $file is a directory and it lacks a trailing slash, add one
- if ((-d $file)) {
- $file =~ s@([^/])$@$1/@;
- } elsif (!(-f $file)) {
- die "$P: file '${file}' not found\n";
+ if ($file ne "&STDIN") {
+ ##if $file is a directory and it lacks a trailing slash, add one
+ if ((-d $file)) {
+ $file =~ s@([^/])$@$1/@;
+ } elsif (!(-f $file)) {
+ die "$P: file '${file}' not found\n";
+ }
}
if ($from_filename) {
push(@files, $file);

2009-12-24 06:46:05

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] scripts/get_maintainer.pl: add support to read patch from STDIN

On Wed, Dec 23, 2009 at 03:27:04PM -0800, Joe Perches wrote:
> On Wed, 2009-12-23 at 14:55 +0100, Borislav Petkov wrote:
> > Teach get_maintainer.pl to read a diff from STDIN
>
> How about this instead?
>
> Doesn't need or accept '-' as a trailing option to read stdin.
> Doesn't print usage() after bad options.
> Adds --usage as command line equivalent of --help

This breaks current usage and possibly other scripts:

# git diff | ./scripts/get_maintainer.pl -
./scripts/get_maintainer.pl: file '-' not found

Just do it as it is done at http://lkml.indiana.edu/hypermail/linux/kernel/0801.1/1654.html

--
Regards/Gruss,
Boris.

2009-12-24 06:48:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] scripts/get_maintainer.pl: add support to read patch from STDIN

On Thu, 2009-12-24 at 07:45 +0100, Borislav Petkov wrote:
> This breaks current usage and possibly other scripts:
>
> # git diff | ./scripts/get_maintainer.pl -
> ./scripts/get_maintainer.pl: file '-' not found
>
> Just do it as it is done at http://lkml.indiana.edu/hypermail/linux/kernel/0801.1/1654.html

How can it break current usage when it's a new feature?


2009-12-24 06:54:08

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] scripts/get_maintainer.pl: add support to read patch from STDIN

On Thu, Dec 24, 2009 at 07:45:56AM +0100, Borislav Petkov wrote:
> On Wed, Dec 23, 2009 at 03:27:04PM -0800, Joe Perches wrote:
> > On Wed, 2009-12-23 at 14:55 +0100, Borislav Petkov wrote:
> > > Teach get_maintainer.pl to read a diff from STDIN
> >
> > How about this instead?
> >
> > Doesn't need or accept '-' as a trailing option to read stdin.
> > Doesn't print usage() after bad options.
> > Adds --usage as command line equivalent of --help
>
> This breaks current usage and possibly other scripts:
>
> # git diff | ./scripts/get_maintainer.pl -
> ./scripts/get_maintainer.pl: file '-' not found

Sorry, too early here. What I meant was that it should be able to
receive both '-' and simply piped input (i.e., without '-'):

git diff | ./scripts/get_maintainer.pl -

as well as

git diff | ./scripts/get_maintainer.pl

IMO.

--
Regards/Gruss,
Boris.