Skip to content

Commit 6f7d98e

Browse files
JoePerchestorvalds
authored andcommitted
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: Joe Perches <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6209ef6 commit 6f7d98e

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

Diff for: scripts/get_maintainer.pl

+66-25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use Getopt::Long qw(:config no_auto_abbrev);
2020
use Cwd;
21+
use File::Find;
2122

2223
my $cur_path = fastgetcwd() . '/';
2324
my $lk_path = "./";
@@ -58,6 +59,7 @@
5859
my $pattern_depth = 0;
5960
my $version = 0;
6061
my $help = 0;
62+
my $find_maintainer_files = 0;
6163

6264
my $vcs_used = 0;
6365

@@ -249,6 +251,7 @@
249251
'sections!' => \$sections,
250252
'fe|file-emails!' => \$file_emails,
251253
'f|file' => \$from_filename,
254+
'find-maintainer-files' => \$find_maintainer_files,
252255
'v|version' => \$version,
253256
'h|help|usage' => \$help,
254257
)) {
@@ -307,36 +310,74 @@
307310

308311
my @typevalue = ();
309312
my %keyword_hash;
313+
my @mfiles = ();
310314

311-
open (my $maint, '<', "${lk_path}MAINTAINERS")
312-
or die "$P: Can't open MAINTAINERS: $!\n";
313-
while (<$maint>) {
314-
my $line = $_;
315-
316-
if ($line =~ m/^([A-Z]):\s*(.*)/) {
317-
my $type = $1;
318-
my $value = $2;
319-
320-
##Filename pattern matching
321-
if ($type eq "F" || $type eq "X") {
322-
$value =~ s@\.@\\\.@g; ##Convert . to \.
323-
$value =~ s/\*/\.\*/g; ##Convert * to .*
324-
$value =~ s/\?/\./g; ##Convert ? to .
325-
##if pattern is a directory and it lacks a trailing slash, add one
326-
if ((-d $value)) {
327-
$value =~ s@([^/])$@$1/@;
315+
sub read_maintainer_file {
316+
my ($file) = @_;
317+
318+
open (my $maint, '<', "$file")
319+
or die "$P: Can't open MAINTAINERS file '$file': $!\n";
320+
while (<$maint>) {
321+
my $line = $_;
322+
323+
if ($line =~ m/^([A-Z]):\s*(.*)/) {
324+
my $type = $1;
325+
my $value = $2;
326+
327+
##Filename pattern matching
328+
if ($type eq "F" || $type eq "X") {
329+
$value =~ s@\.@\\\.@g; ##Convert . to \.
330+
$value =~ s/\*/\.\*/g; ##Convert * to .*
331+
$value =~ s/\?/\./g; ##Convert ? to .
332+
##if pattern is a directory and it lacks a trailing slash, add one
333+
if ((-d $value)) {
334+
$value =~ s@([^/])$@$1/@;
335+
}
336+
} elsif ($type eq "K") {
337+
$keyword_hash{@typevalue} = $value;
328338
}
329-
} elsif ($type eq "K") {
330-
$keyword_hash{@typevalue} = $value;
339+
push(@typevalue, "$type:$value");
340+
} elsif (!(/^\s*$/ || /^\s*\#/)) {
341+
$line =~ s/\n$//g;
342+
push(@typevalue, $line);
331343
}
332-
push(@typevalue, "$type:$value");
333-
} elsif (!/^(\s)*$/) {
334-
$line =~ s/\n$//g;
335-
push(@typevalue, $line);
336344
}
345+
close($maint);
346+
}
347+
348+
sub find_is_maintainer_file {
349+
my ($file) = $_;
350+
return if ($file !~ m@/MAINTAINERS$@);
351+
$file = $File::Find::name;
352+
return if (! -f $file);
353+
push(@mfiles, $file);
337354
}
338-
close($maint);
339355

356+
sub find_ignore_git {
357+
return grep { $_ !~ /^\.git$/; } @_;
358+
}
359+
360+
if (-d "${lk_path}MAINTAINERS") {
361+
opendir(DIR, "${lk_path}MAINTAINERS") or die $!;
362+
my @files = readdir(DIR);
363+
closedir(DIR);
364+
foreach my $file (@files) {
365+
push(@mfiles, "${lk_path}MAINTAINERS/$file") if ($file !~ /^\./);
366+
}
367+
}
368+
369+
if ($find_maintainer_files) {
370+
find( { wanted => \&find_is_maintainer_file,
371+
preprocess => \&find_ignore_git,
372+
no_chdir => 1,
373+
}, "${lk_path}");
374+
} else {
375+
push(@mfiles, "${lk_path}MAINTAINERS") if -f "${lk_path}MAINTAINERS";
376+
}
377+
378+
foreach my $file (@mfiles) {
379+
read_maintainer_file("$file");
380+
}
340381

341382
#
342383
# Read mail address map
@@ -873,7 +914,7 @@ sub top_of_kernel_tree {
873914
if ( (-f "${lk_path}COPYING")
874915
&& (-f "${lk_path}CREDITS")
875916
&& (-f "${lk_path}Kbuild")
876-
&& (-f "${lk_path}MAINTAINERS")
917+
&& (-e "${lk_path}MAINTAINERS")
877918
&& (-f "${lk_path}Makefile")
878919
&& (-f "${lk_path}README")
879920
&& (-d "${lk_path}Documentation")

0 commit comments

Comments
 (0)