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>
23 $0 [-p \$P4PORT] [-bi branch_include] [-be branch_exclude] <change numbers or from..to>
30 @editkind{ qw( add edit delete integrate branch )}
33 my $p4port = $ENV{P4PORT} || 'localhost:1666';
42 if (/^(\d+)\.\.(\d+)?$/) {
43 push @changes, $1 .. ($2 || (split(' ', `p4 changes -m 1`))[1]);
49 $p4port = $1 || shift;
52 push @branch_include, $1 || shift;
55 push @branch_exclude, $1 || shift;
58 warn "Arguments must be change numbers, ignoring `$_'\n";
62 @changes = sort { $b <=> $a } @changes;
64 @branch_include{@branch_include} = @branch_include if @branch_include;
65 @branch_exclude{@branch_exclude} = @branch_exclude if @branch_exclude;
67 my @desc = `p4 -p $p4port describe -s @changes`;
69 die "$0: `p4 -p $p4port describe -s @changes` failed, status[$?]\n";
74 my ($change,$who,$date,$time,@log,$branch,$file,$type,%files);
78 if (/^Change (\d+) by (\w+)\@.+ on (\S+) (\S+)\s*$/) {
79 ($change, $who, $date, $time) = ($1,$2,$3,$4);
80 $_ = shift @desc; # get rid of empty line
87 $_ = shift @desc; # get rid of empty line
88 while ($_ = shift @desc) {
89 last unless /^\.\.\./;
90 if (m{^\.\.\. //depot/(.*?perl|[^/]*)/([^#]+)#\d+ (\w+)\s*$}) {
91 ($branch,$file,$type) = ($1,$2,$3);
93 if (exists $branch_exclude{$branch} or
95 not exists $branch_include{$branch}) {
98 $files{$branch} = {} unless exists $files{$branch};
99 $files{$branch}{$type} = [] unless exists $files{$branch}{$type};
100 push @{$files{$branch}{$type}}, $file;
103 warn "Unknown line [$_], ignoring\n";
108 next if ((not $change) or $skip);
109 print "_" x 76, "\n";
110 printf <<EOT, $change, $who, $date, $time;
111 [%6s] By: %-25s on %9s %9s
118 s/^\[.*\]\s*// unless $i ;
119 # don't print last empty line
125 for my $branch (sort keys %files) {
126 printf "%11s: $branch\n", 'Branch';
127 for my $kind (sort keys %{$files{$branch}}) {
128 warn("### $kind ###\n"), next unless exists $editkind{$kind};
129 my $files = $files{$branch}{$kind};
130 # don't show large branches and integrations
131 $files = ["($kind " . scalar(@$files) . ' files)']
132 if (@$files > 25 && ($kind eq 'integrate'
133 || $kind eq 'branch'))
135 print wrap(sprintf("%12s ", $editkind{$kind}),
136 sprintf("%12s ", $editkind{$kind}),