bump autodie veresion in Maintainers.pl
[p5sagit/p5-mst-13.2.git] / Porting / Maintainers.pm
index 666e451..ee1c7cd 100644 (file)
@@ -18,50 +18,82 @@ use vars qw(@ISA @EXPORT_OK $VERSION);
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(%Modules %Maintainers
                get_module_files get_module_pat
-               show_results process_options files_to_modules);
-$VERSION = 0.02;
+               show_results process_options files_to_modules
+               reload_manifest);
+$VERSION = 0.03;
 require Exporter;
 
 use File::Find;
 use Getopt::Long;
 
 my %MANIFEST;
-if (open(MANIFEST, "MANIFEST")) {
-    while (<MANIFEST>) {
-       if (/^(\S+)\t+(.+)$/) {
-           $MANIFEST{$1}++;
+
+# (re)read the MANIFEST file, blowing away any previous effort
+
+sub reload_manifest {
+    %MANIFEST = ();
+    if (open(MANIFEST, "MANIFEST")) {
+       while (<MANIFEST>) {
+           if (/^(\S+)/) {
+               $MANIFEST{$1}++;
+           }
+           else {
+               warn "MANIFEST:$.: malformed line: $_\n";
+           }
        }
+       close MANIFEST;
+    } else {
+       die "$0: Failed to open MANIFEST for reading: $!\n";
     }
-    close MANIFEST;
-} else {
-    die "$0: Failed to open MANIFEST for reading: $!\n";
 }
 
+reload_manifest;
+
+
 sub get_module_pat {
     my $m = shift;
     split ' ', $Modules{$m}{FILES};
 }
 
+# exand dir/ or foo* into a full list of files
+#
+sub expand_glob {
+    sort { lc $a cmp lc $b }
+       map {
+           -f $_ ? # File as-is.
+               $_ :
+               -d _ ? # Recurse into directories.
+               do {
+                   my @files;
+                   find(
+                        sub {
+                            push @files, $File::Find::name
+                                if -f $_ && exists $MANIFEST{$File::Find::name};
+                        }, $_);
+                   @files;
+               }
+           # The rest are globbable patterns; expand the glob, then
+           # recurively perform directory expansion on any results
+           : expand_glob(grep -e $_,glob($_))
+           } @_;
+}
+
 sub get_module_files {
     my $m = shift;
-    sort { lc $a cmp lc $b }
-    map {
-       -f $_ ? # Files as-is.
-           $_ :
-           -d _ ? # Recurse into directories.
-           do {
-               my @files;
-               find(
-                    sub {
-                        push @files, $File::Find::name
-                            if -f $_ && exists $MANIFEST{$File::Find::name};
-                    }, $_);
-               @files;
-           }
-       : glob($_) # The rest are globbable patterns.
-       } get_module_pat($m);
+    my %exclude;
+    my @files;
+    for (get_module_pat($m)) {
+       if (s/^!//) {
+           $exclude{$_}=1 for expand_glob($_);
+       }
+       else {
+           push @files, expand_glob($_);
+       }
+    }
+    return grep !$exclude{$_}, @files;
 }
 
+
 sub get_maintainer_modules {
     my $m = shift;
     sort { lc $a cmp lc $b }
@@ -79,6 +111,8 @@ $0: Usage: $0 [[--maintainer M --module M --files]|[--check] [commit] | [file ..
                        with a file     checks if it has a maintainer
                        with a dir      checks all files have a maintainer
                        otherwise       checks for multiple maintainers
+--checkmani    like --check, but only reports on unclaimed files if they
+                   are in MANIFEST
 --opened       list all modules of modified files
 Matching is case-ignoring regexp, author matching is both by
 the short id and by the full name and email.  A "module" may
@@ -92,6 +126,7 @@ my $Maintainer;
 my $Module;
 my $Files;
 my $Check;
+my $Checkmani;
 my $Opened;
 
 sub process_options {
@@ -102,6 +137,7 @@ sub process_options {
                       'module=s'       => \$Module,
                       'files'          => \$Files,
                       'check'          => \$Check,
+                      'checkmani'      => \$Checkmani,
                       'opened'         => \$Opened,
                      );
 
@@ -236,9 +272,14 @@ sub show_results {
                }
            }
        }
-    } elsif ($Check) {
+    } elsif ($Check or $Checkmani) {
         if( @Files ) {
-           missing_maintainers( qr{\.(?:[chty]|p[lm]|xs)\z}msx, @Files)
+           missing_maintainers(
+               $Checkmani
+                   ? sub { -f $_ and exists $MANIFEST{$File::Find::name} }
+                   : sub { /\.(?:[chty]|p[lm]|xs)\z/msx },
+               @Files
+           );
        }
        else { 
            duplicated_maintainers();
@@ -296,7 +337,7 @@ sub missing_maintainers {
     for my $d (@path) {
        if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
     }
-    find sub { warn_maintainer($File::Find::name) if /$check/; }, @dir
+    find sub { warn_maintainer($File::Find::name) if $check->() }, @dir
        if @dir;
 }