Initial import of mutt-ng.
[apps/madmutt.git] / cvslog2changelog.pl
1 #!/usr/bin/perl
2
3 # use Data::Dumper;
4
5 %Authors = (roessler => 'Thomas Roessler <roessler@does-not-exist.org>',
6             me => 'Michael Elkins <me@mutt.org>');
7
8 @Changes = ();
9 $change = {};
10
11 while (<>) {
12     chomp $_;
13     if ($_ =~ /^Working file: (.*)$/) {
14         $workfile = $1;
15         $change->{workfile} = $workfile;
16         $change->{logmsg}   = '';
17         $change->{author}   = '';
18         $change->{revision} = '';
19
20 #       print STDERR "workfile: ", $workfile, "\n";
21         
22     } 
23     elsif ($_ =~ /^(=======|------)/) {
24         if ($change->{revision}) {
25             
26             # Some beautifications: Date, author.
27             if ($change->{author} =~ /^(.*?)\s?\<(.*)\>/) {
28                 $change->{author} = "$1  <$2>";
29             }
30             $change->{date} =~ s!/!-!g;
31             
32             # Record the change.
33             push @Changes, $change unless $change->{logmsg} =~ /^#/;
34             $change = {};
35             $change->{workfile} = $workfile;
36             $change->{logmsg}   = '';
37             $change->{author}   = '';
38         }
39     } elsif ($_ =~ /^revision ([0-9.]*)/) {
40         $change->{revision} = $1;
41     } elsif ($_ =~ /^date: ([^; ]*) ([^; ]*);  author: ([^;]*);/) {
42         $change->{date} = $1;
43         $change->{hour} = $2;
44         $change->{author} = $Authors{$3} ? $Authors{$3} : $3;
45         $change->{committed} = $3;
46     } elsif ($_ =~ /^From: (.*)$/) {
47         $change->{author} = $1;
48     } elsif ($change->{revision}) {
49         if ($change->{logmsg} || $_) {
50             $change->{logmsg} .= $_ . "\n";
51         }
52     }
53 }
54
55 # print Dumper @Changes;
56
57 undef $last_logmsg; undef $last_author; undef $last_date; undef $last_hour; undef $last_comm;
58 $files = [];
59
60 for my $k (sort {($b->{date} cmp $a->{date}) || ($b->{hour} cmp $a->{hour}) || ($a->{author} cmp $b->{author}) || ($a->{workfile} cmp $b->{workfile})} @Changes) {
61     
62     if (!($last_date eq $k->{date}) || !($last_author eq $k->{author}) ||
63         !($last_comm eq $k->{committed})) {
64         if (@$files) {
65             &print_entry ($files, $last_logmsg);
66             $files = [];
67         }
68         &print_header ($k->{author}, $k->{committed}, $k->{date}, $k->{hour});
69     }
70  
71     if (@$files && !($last_logmsg eq $k->{logmsg})) {
72         &print_entry ($files, $last_logmsg);
73         $files = [];
74     }
75       
76     
77     $last_comm   = $k->{committed};
78     $last_logmsg = $k->{logmsg};
79     $last_author = $k->{author};
80     $last_date   = $k->{date};
81     $last_hour   = $k->{hour};
82     
83     push @$files, $k->{workfile};
84 }
85
86 if (@$files) {
87     &print_entry ($files, $last_logmsg);
88 }
89
90 sub print_header {
91     my $author = shift;
92     my $committed = shift;
93     my $date = shift;
94     my $hour = shift;
95     
96     print $date, " ", $hour, "  ", $author, "  (", $committed, ")\n\n";
97 }
98
99 sub print_entry  {
100     my $files = shift;
101     my $logmsg = shift;
102     
103
104     print "\t* ";
105     my $c = '';
106     
107     for my $f (@$files) {
108         print $c, $f;
109         $c = ', ' unless $c;
110     }
111     
112     print ": ";
113     
114     my $t = '';
115     for my $l (split ('\n', $logmsg)) {
116         print $t, $l, "\n";
117         $t = "\t" unless $t;
118     }
119     print "\n";
120 }