3 # Generate a nice changelist by querying perforce.
5 # Each change is described with the change number, description,
6 # which branch the change happened in, files modified,
7 # and who was responsible for entering the change.
9 # Can be called with a list of change numbers or a range of the
10 # form "12..42". Changelog will be printed from highest number
13 # Outputs the changelist to stdout.
15 # Gurusamy Sarathy <gsar@activestate.com>
24 $0 [-p \$P4PORT] [-bi branch_include] [-be branch_exclude] <change numbers or from..to>
31 @editkind{ qw( add edit delete integrate branch )}
34 my $p4port = $ENV{P4PORT} || 'localhost:1666';
43 if (/^(\d+)\.\.(\d+)?$/) {
44 push @changes, $1 .. ($2 || (split(' ', `p4 changes -m 1`))[1]);
50 $p4port = $1 || shift;
53 push @branch_include, $1 || shift;
56 push @branch_exclude, $1 || shift;
59 warn "Arguments must be change numbers, ignoring `$_'\n";
63 @changes = sort { $b <=> $a } @changes;
65 @branch_include{@branch_include} = @branch_include if @branch_include;
66 @branch_exclude{@branch_exclude} = @branch_exclude if @branch_exclude;
68 my @desc = `p4 -p $p4port describe -s @changes`;
70 die "$0: `p4 -p $p4port describe -s @changes` failed, status[$?]\n";
73 tr/\r/\n/ foreach @desc;
76 my ($change,$who,$date,$time,@log,$branch,$file,$type,%files);
80 if (/^Change (\d+) by (\w+)\@.+ on (\S+) (\S+)\s*$/) {
81 ($change, $who, $date, $time) = ($1,$2,$3,$4);
82 $_ = shift @desc; # get rid of empty line
89 $_ = shift @desc; # get rid of empty line
90 while ($_ = shift @desc) {
91 last unless /^\.\.\./;
92 if (m{^\.\.\. //depot/(.*?perl|[^/]*)/([^#]+)#\d+ (\w+)\s*$}) {
93 ($branch,$file,$type) = ($1,$2,$3);
95 if (exists $branch_exclude{$branch} or
97 not exists $branch_include{$branch}) {
100 $files{$branch} = {} unless exists $files{$branch};
101 $files{$branch}{$type} = [] unless exists $files{$branch}{$type};
102 push @{$files{$branch}{$type}}, $file;
105 warn "Unknown line [$_], ignoring\n";
110 next if ((not $change) or $skip);
111 my $output = ("_" x 76) . "\n";
112 $output .= sprintf <<EOT, $change, $who, $date, $time;
113 [%6s] By: %-25s on %9s %9s
120 s/^\[.*\]\s*// unless $i ;
121 # don't print last empty line
123 $output .= " " if $i++;
127 for my $branch (sort keys %files) {
128 $output .= sprintf "%11s: $branch\n", 'Branch';
129 for my $kind (sort keys %{$files{$branch}}) {
130 warn("### $kind ###\n"), next unless exists $editkind{$kind};
131 my $files = $files{$branch}{$kind};
132 # don't show large branches and integrations
133 $files = ["($kind " . scalar(@$files) . ' files)']
134 if (@$files > 25 && ($kind eq 'integrate'
135 || $kind eq 'branch'))
137 $output .= wrap(sprintf("%12s ", $editkind{$kind}),
138 sprintf("%12s ", $editkind{$kind}),
142 print unexpand($output);