2 # Maintainers.pm - show information about maintainers
11 require "Maintainers.pl";
12 use vars qw(%Modules %Maintainers);
14 use vars qw(@ISA @EXPORT_OK);
16 @EXPORT_OK = qw(%Modules %Maintainers
17 get_module_files get_module_pat
18 show_results process_options);
25 if (open(MANIFEST, "MANIFEST")) {
27 if (/^(\S+)\t+(.+)$/) {
33 die "$0: Failed to open MANIFEST for reading: $!\n";
38 split ' ', $Modules{$m}{FILES};
41 sub get_module_files {
43 sort { lc $a cmp lc $b }
45 -f $_ ? # Files as-is.
47 -d _ ? # Recurse into directories.
52 push @files, $File::Find::name
53 if -f $_ && exists $MANIFEST{$File::Find::name};
57 : glob($_) # The rest are globbable patterns.
61 sub get_maintainer_modules {
63 sort { lc $a cmp lc $b }
64 grep { $Modules{$_}{MAINTAINER} eq $m }
70 $0: Usage: $0 [[--maintainer M --module M --files --check]|file ...]
71 --maintainer M list all maintainers matching M
72 --module M list all modules matching M
73 --files list all files
74 --check check consistency of Maintainers.pl
75 --opened list all modules of files opened by perforce
76 Matching is case-ignoring regexp, author matching is both by
77 the short id and by the full name and email. A "module" may
78 not be just a module, it may be a file or files or a subdirectory.
79 The options may be abbreviated to their unique prefixes
94 'maintainer=s' => \$Maintainer,
95 'module=s' => \$Module,
104 my @raw = `p4 opened`;
106 @Files = map {s!#.*!!s; s!^//depot/.*?/perl/!!; $_} @raw;
111 usage() if @Files && ($Maintainer || $Module || $Files);
113 for my $mean ($Maintainer, $Module) {
114 warn "$0: Did you mean '$0 $mean'?\n"
115 if $mean && -e $mean && $mean ne '.' && !$Files;
118 warn "$0: Did you mean '$0 -mo $Maintainer'?\n"
119 if defined $Maintainer && exists $Modules{$Maintainer};
121 warn "$0: Did you mean '$0 -ma $Module'?\n"
122 if defined $Module && exists $Maintainers{$Module};
124 return ($Maintainer, $Module, $Files, @Files);
128 my ($Maintainer, $Module, $Files, @Files) = @_;
131 for my $m (sort keys %Maintainers) {
132 if ($m =~ /$Maintainer/io || $Maintainers{$m} =~ /$Maintainer/io) {
133 my @modules = get_maintainer_modules($m);
135 @modules = grep { /$Module/io } @modules;
139 for my $module (@modules) {
140 push @files, get_module_files($module);
142 printf "%-15s @files\n", $m;
145 printf "%-15s @modules\n", $m;
147 printf "%-15s $Maintainers{$m}\n", $m;
153 for my $m (sort { lc $a cmp lc $b } keys %Modules) {
154 if ($m =~ /$Module/io) {
156 my @files = get_module_files($m);
157 printf "%-15s @files\n", $m;
159 printf "%-15s $Modules{$m}{MAINTAINER}\n", $m;
166 for (@Files) { s:^\./:: }
168 @ModuleByFile{@Files} = ();
170 # First try fast match.
173 for my $module (keys %Modules) {
174 for my $pat (get_module_pat($module)) {
175 $ModuleByPat{$pat} = $module;
180 for my $pat (keys %ModuleByPat) {
182 $ExpModuleByPat{$pat} = $ModuleByPat{$pat};
184 for my $exp (glob($pat)) {
185 $ExpModuleByPat{$exp} = $ModuleByPat{$pat};
189 %ModuleByPat = %ExpModuleByPat;
190 for my $file (@Files) {
191 $ModuleByFile{$file} = $ModuleByPat{$file}
192 if exists $ModuleByPat{$file};
195 # If still unresolved files...
196 if (my @ToDo = grep { !defined $ModuleByFile{$_} } keys %ModuleByFile) {
198 # Cannot match what isn't there.
199 @ToDo = grep { -e $_ } @ToDo;
202 # Try prefix matching.
204 # Remove trailing slashes.
205 for (@ToDo) { s|/$|| }
210 for my $pat (keys %ModuleByPat) {
211 last unless keys %ToDo;
214 for my $file (keys %ToDo) {
215 if ($file =~ m|^$pat|i) {
216 $ModuleByFile{$file} = $ModuleByPat{$pat};
226 for my $file (@Files) {
227 if (defined $ModuleByFile{$file}) {
228 my $module = $ModuleByFile{$file};
229 my $maintainer = $Modules{$ModuleByFile{$file}}{MAINTAINER};
230 printf "%-15s $module $maintainer $Maintainers{$maintainer}\n", $file;
232 printf "%-15s ?\n", $file;
237 duplicated_maintainers();
244 sub duplicated_maintainers {
246 for my $k (keys %Modules) {
247 for my $f (get_module_files($k)) {
251 for my $f (keys %files) {
252 if ($files{$f} > 1) {
253 warn "File $f appears $files{$f} times in Maintainers.pl\n";