Commit dcf36a92 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

scripts/get_maintainer.pl: add patch/file search for keywords

Based on an idea from Wolfram Sang.

Add search for MAINTAINERS line "K:" regex pattern match in a patch or file
Matches are added after file pattern matches
Add --keywords command line switch (default 1, on)
Change version to 0.21
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 27480ccc
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
use strict; use strict;
my $P = $0; my $P = $0;
my $V = '0.20'; my $V = '0.21';
use Getopt::Long qw(:config no_auto_abbrev); use Getopt::Long qw(:config no_auto_abbrev);
...@@ -37,6 +37,7 @@ my $scm = 0; ...@@ -37,6 +37,7 @@ my $scm = 0;
my $web = 0; my $web = 0;
my $subsystem = 0; my $subsystem = 0;
my $status = 0; my $status = 0;
my $keywords = 1;
my $from_filename = 0; my $from_filename = 0;
my $pattern_depth = 0; my $pattern_depth = 0;
my $version = 0; my $version = 0;
...@@ -84,6 +85,7 @@ if (!GetOptions( ...@@ -84,6 +85,7 @@ if (!GetOptions(
'scm!' => \$scm, 'scm!' => \$scm,
'web!' => \$web, 'web!' => \$web,
'pattern-depth=i' => \$pattern_depth, 'pattern-depth=i' => \$pattern_depth,
'k|keywords!' => \$keywords,
'f|file' => \$from_filename, 'f|file' => \$from_filename,
'v|version' => \$version, 'v|version' => \$version,
'h|help' => \$help, 'h|help' => \$help,
...@@ -132,6 +134,8 @@ if (!top_of_kernel_tree($lk_path)) { ...@@ -132,6 +134,8 @@ if (!top_of_kernel_tree($lk_path)) {
## Read MAINTAINERS for type/value pairs ## Read MAINTAINERS for type/value pairs
my @typevalue = (); my @typevalue = ();
my %keyword_hash;
open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
while (<MAINT>) { while (<MAINT>) {
my $line = $_; my $line = $_;
...@@ -149,6 +153,8 @@ while (<MAINT>) { ...@@ -149,6 +153,8 @@ while (<MAINT>) {
if ((-d $value)) { if ((-d $value)) {
$value =~ s@([^/])$@$1/@; $value =~ s@([^/])$@$1/@;
} }
} elsif ($type eq "K") {
$keyword_hash{@typevalue} = $value;
} }
push(@typevalue, "$type:$value"); push(@typevalue, "$type:$value");
} elsif (!/^(\s)*$/) { } elsif (!/^(\s)*$/) {
...@@ -188,6 +194,7 @@ if ($email_remove_duplicates) { ...@@ -188,6 +194,7 @@ if ($email_remove_duplicates) {
my @files = (); my @files = ();
my @range = (); my @range = ();
my @keyword_tvi = ();
foreach my $file (@ARGV) { foreach my $file (@ARGV) {
##if $file is a directory and it lacks a trailing slash, add one ##if $file is a directory and it lacks a trailing slash, add one
...@@ -198,11 +205,24 @@ foreach my $file (@ARGV) { ...@@ -198,11 +205,24 @@ foreach my $file (@ARGV) {
} }
if ($from_filename) { if ($from_filename) {
push(@files, $file); push(@files, $file);
if (-f $file && $keywords) {
open(FILE, "<$file") or die "$P: Can't open ${file}\n";
while (<FILE>) {
my $patch_line = $_;
foreach my $line (keys %keyword_hash) {
if ($patch_line =~ m/^.*$keyword_hash{$line}/x) {
push(@keyword_tvi, $line);
}
}
}
close(FILE);
}
} else { } else {
my $file_cnt = @files; my $file_cnt = @files;
my $lastfile; my $lastfile;
open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
while (<PATCH>) { while (<PATCH>) {
my $patch_line = $_;
if (m/^\+\+\+\s+(\S+)/) { if (m/^\+\+\+\s+(\S+)/) {
my $filename = $1; my $filename = $1;
$filename =~ s@^[^/]*/@@; $filename =~ s@^[^/]*/@@;
...@@ -213,6 +233,12 @@ foreach my $file (@ARGV) { ...@@ -213,6 +233,12 @@ foreach my $file (@ARGV) {
if ($email_git_blame) { if ($email_git_blame) {
push(@range, "$lastfile:$1:$2"); push(@range, "$lastfile:$1:$2");
} }
} elsif ($keywords) {
foreach my $line (keys %keyword_hash) {
if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) {
push(@keyword_tvi, $line);
}
}
} }
} }
close(PATCH); close(PATCH);
...@@ -286,6 +312,13 @@ foreach my $file (@files) { ...@@ -286,6 +312,13 @@ foreach my $file (@files) {
} }
} }
if ($keywords) {
@keyword_tvi = sort_and_uniq(@keyword_tvi);
foreach my $line (@keyword_tvi) {
add_categories($line);
}
}
if ($email) { if ($email) {
foreach my $chief (@penguin_chief) { foreach my $chief (@penguin_chief) {
if ($chief =~ m/^(.*):(.*)/) { if ($chief =~ m/^(.*):(.*)/) {
...@@ -384,6 +417,7 @@ Output type options: ...@@ -384,6 +417,7 @@ Output type options:
Other options: Other options:
--pattern-depth => Number of pattern directory traversals (default: 0 (all)) --pattern-depth => Number of pattern directory traversals (default: 0 (all))
--keywords => scan patch for keywords (default: 1 (on))
--version => show version --version => show version
--help => show this help information --help => show this help information
...@@ -486,7 +520,6 @@ sub format_email { ...@@ -486,7 +520,6 @@ sub format_email {
} }
sub find_starting_index { sub find_starting_index {
my ($index) = @_; my ($index) = @_;
while ($index > 0) { while ($index > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment