This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127494] TODO test for $AUTOLOAD being set for DESTROY
[perl5.git] / Porting / core-cpan-diff
index dbfeac7..23ae99f 100644 (file)
@@ -53,7 +53,7 @@ Usage: $0 [opts] [ -d | -v | -x ] [ -a | module ... ]
 -d/--diff     Display file differences using diff(1), rather than just
               listing which files have changed.
 
---diffopts    Options to pass to the diff command. Defaults to '-u'.
+--diffopts    Options to pass to the diff command. Defaults to '-u --binary'.
 
 -f|force      Force download from CPAN of new 02packages.details.txt file
               (with --crosscheck only).
@@ -97,7 +97,7 @@ sub run {
     my $mirror_url = "http://www.cpan.org/";
     my $use_diff;
     my $output_file;
-    my $verbose;
+    my $verbose = 0;
     my $force;
     my $do_crosscheck;
 
@@ -112,22 +112,20 @@ sub run {
         'o|output=s'    => \$output_file,
         'r|reverse'     => \$reverse,
         'u|upstream=s@' => \@wanted_upstreams,
-        'v|verbose'     => \$verbose,
+        'v|verbose:1'   => \$verbose,
         'x|crosscheck'  => \$do_crosscheck,
     ) or usage;
 
-    @wanted_upstreams = map { $_ eq 'undef' ? undef : $_ } @wanted_upstreams;
-
     my @modules;
 
     usage("Cannot mix -a with module list") if $scan_all && @ARGV;
 
     if ($do_crosscheck) {
-        usage("can't use -r, -d, --diffopts, -v with --crosscheck")
-          if ( $reverse || $use_diff || $diff_opts || $verbose );
+        usage("can't use -r, -d, --diffopts with --crosscheck")
+          if ( $reverse || $use_diff || $diff_opts );
     }
     else {
-        $diff_opts = '-u -b' unless defined $diff_opts;
+        $diff_opts = '-u --binary' unless defined $diff_opts;
         usage("can't use -f without --crosscheck") if $force;
     }
 
@@ -166,11 +164,12 @@ sub run {
 
     if ($do_crosscheck) {
         do_crosscheck(
-            $outfh, $cache_dir, $mirror_url,
+            $outfh, $cache_dir, $mirror_url, $verbose,
             $force, \@modules,  \@wanted_upstreams
         );
     }
     else {
+        $verbose > 2 and $use_diff++;
         do_compare(
             \@modules,  $outfh,      $output_file,
             $cache_dir, $mirror_url, $verbose,
@@ -241,7 +240,7 @@ sub do_compare {
             warn "WARNING: duplicate entry for $dist in $module\n";
         }
 
-        my $upstream = $m->{UPSTREAM};
+        my $upstream = $m->{UPSTREAM} // 'undef';
         next if @$wanted_upstreams and !$wanted_upstream{$upstream};
 
         print $outfh "\n$module - "
@@ -339,8 +338,10 @@ EOF
               file_diff( $outfh, $abs_cpan_file, $mapped_file, $reverse,
                 $diff_opts );
             if ( $different && customized( $m, $relative_mapped_file ) ) {
-                if (! $use_diff ) {
-                    print $outfh "  Customized for blead: $relative_mapped_file\n";
+               print $outfh "  Customized for blead: $relative_mapped_file\n";
+                if ( $use_diff && $verbose ) {
+                    $different =~ s{^(--- |\+\+\+ )/tmp/[^/]+/}{$1}gm;
+                    print $outfh $different;
                 }
             }
             elsif ($different) {
@@ -399,6 +400,24 @@ EOF
                 print $outfh "  Perl only: $_\n" unless $use_diff;
             }
         }
+        if ( $verbose ) {
+            foreach my $exclude (@$excluded) {
+                my $seen = 0;
+                foreach my $cpan_file (@cpan_files) {
+                    # may be a simple string to match exactly, or a pattern
+                    if ( ref $exclude ) {
+                        $seen = 1 if $cpan_file =~ $exclude;
+                    }
+                    else {
+                        $seen = 1 if $cpan_file eq $exclude;
+                    }
+                    last if $seen;
+                }
+                if ( not $seen ) {
+                    print $outfh "  Unnecessary exclusion: $exclude\n";
+                }
+            }
+        }
     }
 }
 
@@ -424,7 +443,7 @@ sub distro_base {
 
 sub do_crosscheck {
     my (
-        $outfh, $cache_dir, $mirror_url,
+        $outfh, $cache_dir, $mirror_url, $verbose,
         $force, $modules,   $wanted_upstreams,
     ) = @_;
 
@@ -477,6 +496,8 @@ sub do_crosscheck {
         my $m = $Maintainers::Modules{$module}
           or die "ERROR: No such module in Maintainers.pl: '$module'\n";
 
+        $verbose and warn "Checking $module\n";
+
         unless ( $m->{CPAN} ) {
             print $outfh "\nWARNING: $module is not dual-life; skipping\n";
             next;
@@ -490,7 +511,7 @@ sub do_crosscheck {
         my $pdist = $m->{DISTRIBUTION};
         die "ERROR: $module has no DISTRIBUTION entry\n" unless defined $pdist;
 
-        my $upstream = $m->{UPSTREAM};
+        my $upstream = $m->{UPSTREAM} // 'undef';
         next if @$wanted_upstreams and !$wanted_upstream{$upstream};
 
         my $cdist = $modules{$module};
@@ -505,7 +526,7 @@ sub do_crosscheck {
             if ( keys %$d > 1 ) {
                 print $outfh
                   "\n$module: (found more than one CPAN candidate):\n";
-                print $outfh "    perl: $pdist\n";
+                print $outfh "    Perl: $pdist\n";
                 print $outfh "    CPAN: $_\n" for sort keys %$d;
                 next;
             }
@@ -519,7 +540,7 @@ sub do_crosscheck {
 }
 
 # get the EXCLUDED and MAP entries for this module, or
-# make up defauts if they don't exist
+# make up defaults if they don't exist
 
 sub get_map {
     my ( $m, $module_name, $perl_files ) = @_;