This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
note fixes to FindExt.t
[perl5.git] / Porting / genlog
index efb7ef8..610e976 100755 (executable)
@@ -1,4 +1,4 @@
-#!/l/local/bin/perl -w
+#!/usr/bin/perl -w
 #
 # Generate a nice changelist by querying perforce.
 #
 #
 
 use Text::Wrap;
+use Text::Tabs;
 
 $0 =~ s|^.*/||;
 unless (@ARGV) {
     die <<USAGE;
-        $0 [-p \$P4PORT] <change numbers or from..to>
+        $0 [-p \$P4PORT] [-bi branch_include] [-be branch_exclude] <change numbers or from..to>
 USAGE
 }
 
@@ -32,10 +33,15 @@ my %editkind;
 
 my $p4port = $ENV{P4PORT} || 'localhost:1666';
 
+my @branch_include;
+my @branch_exclude;
+my %branch_include;
+my %branch_exclude;
+
 while (@ARGV) {
     $_ = shift;
-    if (/^(\d+)\.\.(\d+)$/) {
-        push @changes, $1 .. $2;
+    if (/^(\d+)\.\.(\d+)?$/) {
+        push @changes, $1 .. ($2 || (split(' ', `p4 changes -m 1`))[1]);
     }
     elsif (/^\d+$/) {
         push @changes, $_;
@@ -43,6 +49,12 @@ while (@ARGV) {
     elsif (/^-p(.*)$/) {
         $p4port = $1 || shift;
     }
+    elsif (/^-bi(.*)$/) {
+        push @branch_include, $1 || shift;
+    }
+    elsif (/^-be(.*)$/) {
+        push @branch_exclude, $1 || shift;
+    }
     else {
         warn "Arguments must be change numbers, ignoring `$_'\n";
     }
@@ -50,14 +62,20 @@ while (@ARGV) {
 
 @changes = sort { $b <=> $a } @changes;
 
+@branch_include{@branch_include} = @branch_include if @branch_include;
+@branch_exclude{@branch_exclude} = @branch_exclude if @branch_exclude;
+
 my @desc = `p4 -p $p4port describe -s @changes`;
 if ($?) {
     die "$0: `p4 -p $p4port describe -s @changes` failed, status[$?]\n";
 }
 else {
+    tr/\r/\n/ foreach @desc;
     chomp @desc;
     while (@desc) {
        my ($change,$who,$date,$time,@log,$branch,$file,$type,%files);
+       my $skip = 0;
+        my $nbranch = 0;
        $_ = shift @desc;
        if (/^Change (\d+) by (\w+)\@.+ on (\S+) (\S+)\s*$/) {
            ($change, $who, $date, $time) = ($1,$2,$3,$4);
@@ -73,6 +91,12 @@ else {
                    last unless /^\.\.\./;
                    if (m{^\.\.\. //depot/(.*?perl|[^/]*)/([^#]+)#\d+ (\w+)\s*$}) {
                        ($branch,$file,$type) = ($1,$2,$3);
+                       $nbranch++;
+                       if (exists $branch_exclude{$branch} or
+                           @branch_include and
+                           not exists $branch_include{$branch}) {
+                           $skip++;
+                       }
                        $files{$branch} = {} unless exists $files{$branch};
                        $files{$branch}{$type} = [] unless exists $files{$branch}{$type};
                        push @{$files{$branch}{$type}}, $file;
@@ -83,12 +107,12 @@ else {
                }
            }
        }
-       next unless $change;
-       print "_" x 76, "\n";
-       printf <<EOT, $change, $who, $date, $time;
+       next if ((not $change) or $skip);
+       my $output = ("_" x 76) . "\n";
+       $output .= sprintf <<EOT, $change, $who, $date, $time;
 [%6s] By: %-25s             on %9s %9s
 EOT
-       print "        Log: ";
+       $output .= "        Log: ";
        my $i = 0;
        while (@log) {
            $_ = shift @log;
@@ -96,12 +120,12 @@ EOT
            s/^\[.*\]\s*// unless $i ;
             # don't print last empty line
            if ($_ or @log) {
-               print "             " if $i++;
-               print "$_\n";
+               $output .= "             " if $i++;
+               $output .= "$_\n";
            }
        }
        for my $branch (sort keys %files) {
-           printf "%11s: $branch\n", 'Branch';
+           $output .= sprintf "%11s: $branch\n", 'Branch';
            for my $kind (sort keys %{$files{$branch}}) {
                warn("### $kind ###\n"), next unless exists $editkind{$kind};
                my $files = $files{$branch}{$kind};
@@ -110,10 +134,11 @@ EOT
                    if (@$files > 25 && ($kind eq 'integrate'
                                         || $kind eq 'branch'))
                       || @$files > 100;
-               print wrap(sprintf("%12s ", $editkind{$kind}),
-                          sprintf("%12s ", $editkind{$kind}),
-                          "@$files\n");
+               $output .= wrap(sprintf("%12s ", $editkind{$kind}),
+                               sprintf("%12s ", $editkind{$kind}),
+                               "@$files\n");
             }
        }
+       print unexpand($output);
     }
 }