Commit 6f7d98ec authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

get_maintainer: Prepare for separate MAINTAINERS files

Allow for MAINTAINERS to become a directory and if it is,
read all the files in the directory for maintained sections.

Optionally look for all files named MAINTAINERS in directories
excluding the .git directory by using --find-maintainer-files.

This optional feature adds ~.3 seconds of CPU on an Intel
i5-6200 with an SSD.

Miscellanea:

 - Create a read_maintainer_file subroutine from the existing code
 - Test only the existence of MAINTAINERS, not whether it's a file
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6209ef67
...@@ -18,6 +18,7 @@ my $V = '0.26'; ...@@ -18,6 +18,7 @@ my $V = '0.26';
use Getopt::Long qw(:config no_auto_abbrev); use Getopt::Long qw(:config no_auto_abbrev);
use Cwd; use Cwd;
use File::Find;
my $cur_path = fastgetcwd() . '/'; my $cur_path = fastgetcwd() . '/';
my $lk_path = "./"; my $lk_path = "./";
...@@ -58,6 +59,7 @@ my $from_filename = 0; ...@@ -58,6 +59,7 @@ my $from_filename = 0;
my $pattern_depth = 0; my $pattern_depth = 0;
my $version = 0; my $version = 0;
my $help = 0; my $help = 0;
my $find_maintainer_files = 0;
my $vcs_used = 0; my $vcs_used = 0;
...@@ -249,6 +251,7 @@ if (!GetOptions( ...@@ -249,6 +251,7 @@ if (!GetOptions(
'sections!' => \$sections, 'sections!' => \$sections,
'fe|file-emails!' => \$file_emails, 'fe|file-emails!' => \$file_emails,
'f|file' => \$from_filename, 'f|file' => \$from_filename,
'find-maintainer-files' => \$find_maintainer_files,
'v|version' => \$version, 'v|version' => \$version,
'h|help|usage' => \$help, 'h|help|usage' => \$help,
)) { )) {
...@@ -307,36 +310,74 @@ if (!top_of_kernel_tree($lk_path)) { ...@@ -307,36 +310,74 @@ if (!top_of_kernel_tree($lk_path)) {
my @typevalue = (); my @typevalue = ();
my %keyword_hash; my %keyword_hash;
my @mfiles = ();
open (my $maint, '<', "${lk_path}MAINTAINERS") sub read_maintainer_file {
or die "$P: Can't open MAINTAINERS: $!\n"; my ($file) = @_;
while (<$maint>) {
my $line = $_; open (my $maint, '<', "$file")
or die "$P: Can't open MAINTAINERS file '$file': $!\n";
if ($line =~ m/^([A-Z]):\s*(.*)/) { while (<$maint>) {
my $type = $1; my $line = $_;
my $value = $2;
if ($line =~ m/^([A-Z]):\s*(.*)/) {
##Filename pattern matching my $type = $1;
if ($type eq "F" || $type eq "X") { my $value = $2;
$value =~ s@\.@\\\.@g; ##Convert . to \.
$value =~ s/\*/\.\*/g; ##Convert * to .* ##Filename pattern matching
$value =~ s/\?/\./g; ##Convert ? to . if ($type eq "F" || $type eq "X") {
##if pattern is a directory and it lacks a trailing slash, add one $value =~ s@\.@\\\.@g; ##Convert . to \.
if ((-d $value)) { $value =~ s/\*/\.\*/g; ##Convert * to .*
$value =~ s@([^/])$@$1/@; $value =~ s/\?/\./g; ##Convert ? to .
##if pattern is a directory and it lacks a trailing slash, add one
if ((-d $value)) {
$value =~ s@([^/])$@$1/@;
}
} elsif ($type eq "K") {
$keyword_hash{@typevalue} = $value;
} }
} elsif ($type eq "K") { push(@typevalue, "$type:$value");
$keyword_hash{@typevalue} = $value; } elsif (!(/^\s*$/ || /^\s*\#/)) {
$line =~ s/\n$//g;
push(@typevalue, $line);
} }
push(@typevalue, "$type:$value");
} elsif (!/^(\s)*$/) {
$line =~ s/\n$//g;
push(@typevalue, $line);
} }
close($maint);
}
sub find_is_maintainer_file {
my ($file) = $_;
return if ($file !~ m@/MAINTAINERS$@);
$file = $File::Find::name;
return if (! -f $file);
push(@mfiles, $file);
} }
close($maint);
sub find_ignore_git {
return grep { $_ !~ /^\.git$/; } @_;
}
if (-d "${lk_path}MAINTAINERS") {
opendir(DIR, "${lk_path}MAINTAINERS") or die $!;
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
push(@mfiles, "${lk_path}MAINTAINERS/$file") if ($file !~ /^\./);
}
}
if ($find_maintainer_files) {
find( { wanted => \&find_is_maintainer_file,
preprocess => \&find_ignore_git,
no_chdir => 1,
}, "${lk_path}");
} else {
push(@mfiles, "${lk_path}MAINTAINERS") if -f "${lk_path}MAINTAINERS";
}
foreach my $file (@mfiles) {
read_maintainer_file("$file");
}
# #
# Read mail address map # Read mail address map
...@@ -873,7 +914,7 @@ sub top_of_kernel_tree { ...@@ -873,7 +914,7 @@ sub top_of_kernel_tree {
if ( (-f "${lk_path}COPYING") if ( (-f "${lk_path}COPYING")
&& (-f "${lk_path}CREDITS") && (-f "${lk_path}CREDITS")
&& (-f "${lk_path}Kbuild") && (-f "${lk_path}Kbuild")
&& (-f "${lk_path}MAINTAINERS") && (-e "${lk_path}MAINTAINERS")
&& (-f "${lk_path}Makefile") && (-f "${lk_path}Makefile")
&& (-f "${lk_path}README") && (-f "${lk_path}README")
&& (-d "${lk_path}Documentation") && (-d "${lk_path}Documentation")
......
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