A slightly better layout for the diagram.
[p5sagit/p5-mst-13.2.git] / Porting / genlog
CommitLineData
23b3bd7f 1#!/usr/bin/perl -w
808270a4 2#
3# Generate a nice changelist by querying perforce.
4#
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.
8#
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
11# to lowest.
12#
13# Outputs the changelist to stdout.
14#
6e238990 15# Gurusamy Sarathy <gsar@activestate.com>
808270a4 16#
17
18use Text::Wrap;
19
20$0 =~ s|^.*/||;
21unless (@ARGV) {
22 die <<USAGE;
2ebe8b91 23 $0 [-p \$P4PORT] [-bi branch_include] [-be branch_exclude] <change numbers or from..to>
808270a4 24USAGE
25}
26
27my @changes;
28
29my %editkind;
30@editkind{ qw( add edit delete integrate branch )}
31 = qw( + ! - !> +> );
32
33my $p4port = $ENV{P4PORT} || 'localhost:1666';
34
2ebe8b91 35my @branch_include;
36my @branch_exclude;
37my %branch_include;
38my %branch_exclude;
39
808270a4 40while (@ARGV) {
41 $_ = shift;
18a48444 42 if (/^(\d+)\.\.(\d+)?$/) {
43 push @changes, $1 .. ($2 || (split(' ', `p4 changes -m 1`))[1]);
808270a4 44 }
45 elsif (/^\d+$/) {
46 push @changes, $_;
47 }
48 elsif (/^-p(.*)$/) {
49 $p4port = $1 || shift;
50 }
2ebe8b91 51 elsif (/^-bi(.*)$/) {
52 push @branch_include, $1 || shift;
53 }
54 elsif (/^-be(.*)$/) {
55 push @branch_exclude, $1 || shift;
56 }
808270a4 57 else {
58 warn "Arguments must be change numbers, ignoring `$_'\n";
59 }
60}
61
62@changes = sort { $b <=> $a } @changes;
63
2ebe8b91 64@branch_include{@branch_include} = @branch_include if @branch_include;
65@branch_exclude{@branch_exclude} = @branch_exclude if @branch_exclude;
66
808270a4 67my @desc = `p4 -p $p4port describe -s @changes`;
68if ($?) {
69 die "$0: `p4 -p $p4port describe -s @changes` failed, status[$?]\n";
70}
71else {
72 chomp @desc;
73 while (@desc) {
74 my ($change,$who,$date,$time,@log,$branch,$file,$type,%files);
2ebe8b91 75 my $skip = 0;
0b3b9d72 76 my $nbranch = 0;
808270a4 77 $_ = shift @desc;
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
81 while (@desc) {
82 $_ = shift @desc;
83 last if /^Affected/;
84 push @log, $_;
85 }
86 if (/^Affected/) {
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);
0b3b9d72 92 $nbranch++;
2ebe8b91 93 if (exists $branch_exclude{$branch} or
94 @branch_include and
95 not exists $branch_include{$branch}) {
96 $skip++;
97 }
808270a4 98 $files{$branch} = {} unless exists $files{$branch};
99 $files{$branch}{$type} = [] unless exists $files{$branch}{$type};
100 push @{$files{$branch}{$type}}, $file;
101 }
102 else {
103 warn "Unknown line [$_], ignoring\n";
104 }
105 }
106 }
107 }
18a48444 108 next if ((not $change) or $skip);
808270a4 109 print "_" x 76, "\n";
110 printf <<EOT, $change, $who, $date, $time;
111[%6s] By: %-25s on %9s %9s
112EOT
113 print " Log: ";
114 my $i = 0;
115 while (@log) {
116 $_ = shift @log;
117 s/^\s*//;
118 s/^\[.*\]\s*// unless $i ;
119 # don't print last empty line
120 if ($_ or @log) {
121 print " " if $i++;
122 print "$_\n";
123 }
124 }
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)']
6abf89b4 132 if (@$files > 25 && ($kind eq 'integrate'
133 || $kind eq 'branch'))
134 || @$files > 100;
808270a4 135 print wrap(sprintf("%12s ", $editkind{$kind}),
136 sprintf("%12s ", $editkind{$kind}),
137 "@$files\n");
138 }
139 }
140 }
141}