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);
29 if (open(MANIFEST, "MANIFEST")) {
31 if (/^(\S+)\t+(.+)$/) {
37 die "$0: Failed to open MANIFEST for reading: $!\n";
42 split ' ', $Modules{$m}{FILES};
45 sub get_module_files {
47 sort { lc $a cmp lc $b }
49 -f $_ ? # Files as-is.
51 -d _ ? # Recurse into directories.
56 push @files, $File::Find::name
57 if -f $_ && exists $MANIFEST{$File::Find::name};
61 : glob($_) # The rest are globbable patterns.
65 sub get_maintainer_modules {
67 sort { lc $a cmp lc $b }
68 grep { $Modules{$_}{MAINTAINER} eq $m }
74 $0: Usage: $0 [[--maintainer M --module M --files]|[--check] file ...]
75 --maintainer M list all maintainers matching M
76 --module M list all modules matching M
77 --files list all files
78 --check check consistency of Maintainers.pl
79 with a file checks if it has a maintainer
80 with a dir checks all files have a maintainer
81 otherwise checks for multiple maintainers
82 --opened list all modules of files opened by perforce
83 Matching is case-ignoring regexp, author matching is both by
84 the short id and by the full name and email. A "module" may
85 not be just a module, it may be a file or files or a subdirectory.
86 The options may be abbreviated to their unique prefixes
101 'maintainer=s' => \$Maintainer,
102 'module=s' => \$Module,
105 'opened' => \$Opened,
111 @Files = `p4 opened`;
115 s!^//depot/(?:perl|.*?/perl)/!!;
121 usage() if @Files && ($Maintainer || $Module || $Files);
123 for my $mean ($Maintainer, $Module) {
124 warn "$0: Did you mean '$0 $mean'?\n"
125 if $mean && -e $mean && $mean ne '.' && !$Files;
128 warn "$0: Did you mean '$0 -mo $Maintainer'?\n"
129 if defined $Maintainer && exists $Modules{$Maintainer};
131 warn "$0: Did you mean '$0 -ma $Module'?\n"
132 if defined $Module && exists $Maintainers{$Module};
134 return ($Maintainer, $Module, $Files, @Files);
138 my ($Maintainer, $Module, $Files, @Files) = @_;
141 for my $m (sort keys %Maintainers) {
142 if ($m =~ /$Maintainer/io || $Maintainers{$m} =~ /$Maintainer/io) {
143 my @modules = get_maintainer_modules($m);
145 @modules = grep { /$Module/io } @modules;
149 for my $module (@modules) {
150 push @files, get_module_files($module);
152 printf "%-15s @files\n", $m;
155 printf "%-15s @modules\n", $m;
157 printf "%-15s $Maintainers{$m}\n", $m;
163 for my $m (sort { lc $a cmp lc $b } keys %Modules) {
164 if ($m =~ /$Module/io) {
166 my @files = get_module_files($m);
167 printf "%-15s @files\n", $m;
169 printf "%-15s $Modules{$m}{MAINTAINER}\n", $m;
175 missing_maintainers( qr{\.(?:[chty]|p[lm]|xs)\z}msx, @Files)
178 duplicated_maintainers();
183 for (@Files) { s:^\./:: }
185 @ModuleByFile{@Files} = ();
187 # First try fast match.
190 for my $module (keys %Modules) {
191 for my $pat (get_module_pat($module)) {
192 $ModuleByPat{$pat} = $module;
197 for my $pat (keys %ModuleByPat) {
199 $ExpModuleByPat{$pat} = $ModuleByPat{$pat};
201 for my $exp (glob($pat)) {
202 $ExpModuleByPat{$exp} = $ModuleByPat{$pat};
206 %ModuleByPat = %ExpModuleByPat;
207 for my $file (@Files) {
208 $ModuleByFile{$file} = $ModuleByPat{$file}
209 if exists $ModuleByPat{$file};
212 # If still unresolved files...
213 if (my @ToDo = grep { !defined $ModuleByFile{$_} } keys %ModuleByFile) {
215 # Cannot match what isn't there.
216 @ToDo = grep { -e $_ } @ToDo;
219 # Try prefix matching.
221 # Remove trailing slashes.
222 for (@ToDo) { s|/$|| }
227 for my $pat (keys %ModuleByPat) {
228 last unless keys %ToDo;
231 for my $file (keys %ToDo) {
232 if ($file =~ m|^$pat|i) {
233 $ModuleByFile{$file} = $ModuleByPat{$pat};
243 for my $file (@Files) {
244 if (defined $ModuleByFile{$file}) {
245 my $module = $ModuleByFile{$file};
246 my $maintainer = $Modules{$ModuleByFile{$file}}{MAINTAINER};
247 printf "%-15s $module $maintainer $Maintainers{$maintainer}\n", $file;
249 printf "%-15s ?\n", $file;
260 sub maintainers_files {
262 for my $k (keys %Modules) {
263 for my $f (get_module_files($k)) {
269 sub duplicated_maintainers {
271 for my $f (keys %files) {
272 if ($files{$f} > 1) {
273 warn "File $f appears $files{$f} times in Maintainers.pl\n";
278 sub warn_maintainer {
280 warn "File $name has no maintainer\n" if not $files{$name};
283 sub missing_maintainers {
284 my($check, @path) = @_;
288 if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
290 find sub { warn_maintainer($File::Find::name) if /$check/; }, @dir