2 # Maintainers.pm - show information about maintainers
11 # Please don't use post 5.008 features as this module is used by
12 # Porting/makemeta, and that in turn has to be run by the perl just built.
15 require "Maintainers.pl";
16 our (%Modules, %Maintainers);
18 our @ISA = qw(Exporter);
19 our @EXPORT_OK = qw(%Modules %Maintainers
20 get_module_files get_module_pat
21 show_results process_options files_to_modules
33 # (re)read the MANIFEST file, blowing away any previous effort
38 my $manifest_path = 'MANIFEST';
39 if (! -e $manifest_path) {
40 $manifest_path = "../MANIFEST";
43 if (open(my $manfh, '<', $manifest_path )) {
49 warn "MANIFEST:$.: malformed line: $_\n";
54 die "$0: Failed to open MANIFEST for reading: $!\n";
63 split ' ', $Modules{$m}{FILES};
66 # expand dir/ or foo* into a full list of files
69 sort { lc $a cmp lc $b }
71 -f $_ && $_ !~ /[*?]/ ? # File as-is.
73 -d _ && $_ !~ /[*?]/ ? # Recurse into directories.
78 push @files, $File::Find::name
79 if -f $_ && exists $MANIFEST{$File::Find::name};
83 # Not a glob, but doesn't exist
85 # The rest are globbable patterns; expand the glob, then
86 # recursively perform directory expansion on any results
87 : expand_glob(glob($_))
94 my $excluded = $Modules{$m}{EXCLUDED};
96 unless $excluded and @$excluded;
98 my ($pat) = map { qr/$_/ } join '|' => map {
99 ref $_ ? $_ : qr/\b\Q$_\E$/
102 return grep { $_ !~ $pat } @files;
105 sub get_module_files {
107 return filter_excluded $m => map { expand_glob($_) } get_module_pat($m);
111 sub get_maintainer_modules {
113 sort { lc $a cmp lc $b }
114 grep { $Modules{$_}{MAINTAINER} eq $m }
121 --maintainer M | --module M [--files]
122 List modules or maintainers matching the pattern M.
123 With --files, list all the files associated with them
125 --check | --checkmani [commit | file ... | dir ... ]
126 Check consistency of Maintainers.pl
127 with a file checks if it has a maintainer
128 with a dir checks all files have a maintainer
129 with a commit checks files modified by that commit
130 no arg checks for multiple maintainers
131 --checkmani is like --check, but only reports on unclaimed
132 files if they are in MANIFEST
135 List the module ownership of modified or the listed files
137 Matching is case-ignoring regexp, author matching is both by
138 the short id and by the full name and email. A "module" may
139 not be just a module, it may be a file or files or a subdirectory.
140 The options may be abbreviated to their unique prefixes
153 sub process_options {
157 'maintainer=s' => \$Maintainer,
158 'module=s' => \$Module,
161 'checkmani' => \$Checkmani,
162 'opened' => \$Opened,
169 chomp (@Files = `git ls-files -m --full-name`);
171 } elsif (@ARGV == 1 &&
172 $ARGV[0] =~ /^(?:HEAD|[0-9a-f]{4,40})(?:~\d+)?\^*$/) {
173 my $command = "git diff --name-only $ARGV[0]^ $ARGV[0]";
174 chomp (@Files = `$command`);
175 die "'$command' failed: $?" if $?;
180 usage() if @Files && ($Maintainer || $Module || $Files);
182 for my $mean ($Maintainer, $Module) {
183 warn "$0: Did you mean '$0 $mean'?\n"
184 if $mean && -e $mean && $mean ne '.' && !$Files;
187 warn "$0: Did you mean '$0 -mo $Maintainer'?\n"
188 if defined $Maintainer && exists $Modules{$Maintainer};
190 warn "$0: Did you mean '$0 -ma $Module'?\n"
191 if defined $Module && exists $Maintainers{$Module};
193 return ($Maintainer, $Module, $Files, @Files);
196 sub files_to_modules {
200 for (@Files) { s:^\./:: }
202 @ModuleByFile{@Files} = ();
204 # First try fast match.
207 for my $module (keys %Modules) {
208 for my $pat (get_module_pat($module)) {
209 $ModuleByPat{$pat} = $module;
214 for my $pat (keys %ModuleByPat) {
216 $ExpModuleByPat{$pat} = $ModuleByPat{$pat};
218 for my $exp (glob($pat)) {
219 $ExpModuleByPat{$exp} = $ModuleByPat{$pat};
223 %ModuleByPat = %ExpModuleByPat;
224 for my $file (@Files) {
225 $ModuleByFile{$file} = $ModuleByPat{$file}
226 if exists $ModuleByPat{$file};
229 # If still unresolved files...
230 if (my @ToDo = grep { !defined $ModuleByFile{$_} } keys %ModuleByFile) {
232 # Cannot match what isn't there.
233 @ToDo = grep { -e $_ } @ToDo;
236 # Try prefix matching.
238 # Need to try longest prefixes first, else lib/CPAN may match
239 # lib/CPANPLUS/... and similar
241 my @OrderedModuleByPat
242 = sort {length $b <=> length $a} keys %ModuleByPat;
244 # Remove trailing slashes.
245 for (@ToDo) { s|/$|| }
250 for my $pat (@OrderedModuleByPat) {
251 last unless keys %ToDo;
254 for my $file (keys %ToDo) {
255 if ($file =~ m|^$pat|i) {
256 $ModuleByFile{$file} = $ModuleByPat{$pat};
268 my ($Maintainer, $Module, $Files, @Files) = @_;
271 for my $m (sort keys %Maintainers) {
272 if ($m =~ /$Maintainer/io || $Maintainers{$m} =~ /$Maintainer/io) {
273 my @modules = get_maintainer_modules($m);
275 @modules = grep { /$Module/io } @modules;
279 for my $module (@modules) {
280 push @files, get_module_files($module);
282 printf "%-15s @files\n", $m;
285 printf "%-15s @modules\n", $m;
287 printf "%-15s $Maintainers{$m}\n", $m;
293 for my $m (sort { lc $a cmp lc $b } keys %Modules) {
294 if ($m =~ /$Module/io) {
296 my @files = get_module_files($m);
297 printf "%-15s @files\n", $m;
299 printf "%-15s %-12s %s\n", $m, $Modules{$m}{MAINTAINER}, $Modules{$m}{UPSTREAM}||'unknown';
303 } elsif ($Check or $Checkmani) {
309 ? sub { -f $_ and exists $MANIFEST{$File::Find::name} }
310 : sub { /\.(?:[chty]|p[lm]|xs)\z/msx },
314 duplicated_maintainers();
315 superfluous_maintainers();
318 my $ModuleByFile = files_to_modules(@Files);
319 for my $file (@Files) {
320 if (defined $ModuleByFile->{$file}) {
321 my $module = $ModuleByFile->{$file};
322 my $maintainer = $Modules{$ModuleByFile->{$file}}{MAINTAINER};
323 my $upstream = $Modules{$module}{UPSTREAM}||'unknown';
324 printf "%-15s [%-7s] $module $maintainer $Maintainers{$maintainer}\n", $file, $upstream;
326 printf "%-15s ?\n", $file;
331 print STDERR "(No files are modified)\n";
340 sub maintainers_files {
342 for my $k (keys %Modules) {
343 for my $f (get_module_files($k)) {
349 sub duplicated_maintainers {
351 for my $f (sort keys %files) {
352 cmp_ok($files{$f}, '<=', 1, "File $f appears $files{$f} times in Maintainers.pl");
356 sub warn_maintainer {
358 ok($files{$name}, "$name has a maintainer (see Porting/Maintainers.pl)");
361 sub missing_maintainers {
362 my($check, @path) = @_;
366 if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
368 find sub { warn_maintainer($File::Find::name) if $check->() }, @dir if @dir;
371 sub superfluous_maintainers {
373 for my $f (sort keys %files) {
374 ok($MANIFEST{$f}, "File $f has a maintainer and is in MANIFEST");
378 sub finish_tap_output {