2 # Maintainers.pm - show information about maintainers
10 # Please don't use post 5.008 features as this module is used by
11 # Porting/makemeta, and that in turn has to be run by the perl just built.
14 require "Maintainers.pl";
15 use vars qw(%Modules %Maintainers);
17 use vars qw(@ISA @EXPORT_OK $VERSION);
19 @EXPORT_OK = qw(%Modules %Maintainers
20 get_module_files get_module_pat
21 show_results process_options files_to_modules
31 # (re)read the MANIFEST file, blowing away any previous effort
35 if (open(MANIFEST, "MANIFEST")) {
41 warn "MANIFEST:$.: malformed line: $_\n";
46 die "$0: Failed to open MANIFEST for reading: $!\n";
55 split ' ', $Modules{$m}{FILES};
58 # exand dir/ or foo* into a full list of files
61 sort { lc $a cmp lc $b }
65 -d _ ? # Recurse into directories.
70 push @files, $File::Find::name
71 if -f $_ && exists $MANIFEST{$File::Find::name};
75 # The rest are globbable patterns; expand the glob, then
76 # recurively perform directory expansion on any results
77 : expand_glob(grep -e $_,glob($_))
81 sub get_module_files {
85 for (get_module_pat($m)) {
87 $exclude{$_}=1 for expand_glob($_);
90 push @files, expand_glob($_);
93 return grep !$exclude{$_}, @files;
97 sub get_maintainer_modules {
99 sort { lc $a cmp lc $b }
100 grep { $Modules{$_}{MAINTAINER} eq $m }
106 $0: Usage: $0 [[--maintainer M --module M --files]|[--check] [commit] | [file ...]
107 --maintainer M list all maintainers matching M
108 --module M list all modules matching M
109 --files list all files
110 --check check consistency of Maintainers.pl
111 with a file checks if it has a maintainer
112 with a dir checks all files have a maintainer
113 otherwise checks for multiple maintainers
114 --checkmani like --check, but only reports on unclaimed files if they
116 --opened list all modules of modified files
117 Matching is case-ignoring regexp, author matching is both by
118 the short id and by the full name and email. A "module" may
119 not be just a module, it may be a file or files or a subdirectory.
120 The options may be abbreviated to their unique prefixes
132 sub process_options {
136 'maintainer=s' => \$Maintainer,
137 'module=s' => \$Module,
140 'checkmani' => \$Checkmani,
141 'opened' => \$Opened,
147 chomp (@Files = `git ls-files -m --full-name`);
149 } elsif (@ARGV == 1 &&
150 $ARGV[0] =~ /^(?:HEAD|[0-9a-f]{4,40})(?:~\d+)?\^*$/) {
151 my $command = "git diff --name-only $ARGV[0]^ $ARGV[0]";
152 chomp (@Files = `$command`);
153 die "'$command' failed: $?" if $?;
158 usage() if @Files && ($Maintainer || $Module || $Files);
160 for my $mean ($Maintainer, $Module) {
161 warn "$0: Did you mean '$0 $mean'?\n"
162 if $mean && -e $mean && $mean ne '.' && !$Files;
165 warn "$0: Did you mean '$0 -mo $Maintainer'?\n"
166 if defined $Maintainer && exists $Modules{$Maintainer};
168 warn "$0: Did you mean '$0 -ma $Module'?\n"
169 if defined $Module && exists $Maintainers{$Module};
171 return ($Maintainer, $Module, $Files, @Files);
174 sub files_to_modules {
178 for (@Files) { s:^\./:: }
180 @ModuleByFile{@Files} = ();
182 # First try fast match.
185 for my $module (keys %Modules) {
186 for my $pat (get_module_pat($module)) {
187 $ModuleByPat{$pat} = $module;
192 for my $pat (keys %ModuleByPat) {
194 $ExpModuleByPat{$pat} = $ModuleByPat{$pat};
196 for my $exp (glob($pat)) {
197 $ExpModuleByPat{$exp} = $ModuleByPat{$pat};
201 %ModuleByPat = %ExpModuleByPat;
202 for my $file (@Files) {
203 $ModuleByFile{$file} = $ModuleByPat{$file}
204 if exists $ModuleByPat{$file};
207 # If still unresolved files...
208 if (my @ToDo = grep { !defined $ModuleByFile{$_} } keys %ModuleByFile) {
210 # Cannot match what isn't there.
211 @ToDo = grep { -e $_ } @ToDo;
214 # Try prefix matching.
216 # Remove trailing slashes.
217 for (@ToDo) { s|/$|| }
222 for my $pat (keys %ModuleByPat) {
223 last unless keys %ToDo;
226 for my $file (keys %ToDo) {
227 if ($file =~ m|^$pat|i) {
228 $ModuleByFile{$file} = $ModuleByPat{$pat};
240 my ($Maintainer, $Module, $Files, @Files) = @_;
243 for my $m (sort keys %Maintainers) {
244 if ($m =~ /$Maintainer/io || $Maintainers{$m} =~ /$Maintainer/io) {
245 my @modules = get_maintainer_modules($m);
247 @modules = grep { /$Module/io } @modules;
251 for my $module (@modules) {
252 push @files, get_module_files($module);
254 printf "%-15s @files\n", $m;
257 printf "%-15s @modules\n", $m;
259 printf "%-15s $Maintainers{$m}\n", $m;
265 for my $m (sort { lc $a cmp lc $b } keys %Modules) {
266 if ($m =~ /$Module/io) {
268 my @files = get_module_files($m);
269 printf "%-15s @files\n", $m;
271 printf "%-15s %-12s %s\n", $m, $Modules{$m}{MAINTAINER}, $Modules{$m}{UPSTREAM}||'unknown';
275 } elsif ($Check or $Checkmani) {
279 ? sub { -f $_ and exists $MANIFEST{$File::Find::name} }
280 : sub { /\.(?:[chty]|p[lm]|xs)\z/msx },
285 duplicated_maintainers();
288 my $ModuleByFile = files_to_modules(@Files);
289 for my $file (@Files) {
290 if (defined $ModuleByFile->{$file}) {
291 my $module = $ModuleByFile->{$file};
292 my $maintainer = $Modules{$ModuleByFile->{$file}}{MAINTAINER};
293 my $upstream = $Modules{$module}{UPSTREAM}||'unknown';
294 printf "%-15s [%-7s] $module $maintainer $Maintainers{$maintainer}\n", $file, $upstream;
296 printf "%-15s ?\n", $file;
301 print STDERR "(No files are modified)\n";
310 sub maintainers_files {
312 for my $k (keys %Modules) {
313 for my $f (get_module_files($k)) {
319 sub duplicated_maintainers {
321 for my $f (keys %files) {
322 if ($files{$f} > 1) {
323 warn "File $f appears $files{$f} times in Maintainers.pl\n";
328 sub warn_maintainer {
330 warn "File $name has no maintainer\n" if not $files{$name};
333 sub missing_maintainers {
334 my($check, @path) = @_;
338 if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
340 find sub { warn_maintainer($File::Find::name) if $check->() }, @dir