Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / debian / scripts / mergechangelogs
1 #! /usr/bin/perl
2 # mergechangelogs -- Tool to merge Debian changelogs
3 #
4 # Copyright (C) 2006 Nokia
5 #
6 # This program is free software.  It is distributed under the terms of
7 # the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any
9 # later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21
22 use strict;
23 use warnings;
24
25 my @logs = ([]);
26
27 # Read changelogs.
28 foreach my $file ( @ARGV ) {
29         local $/;
30         open LOG,'<',$file or die;
31         push @logs, [
32                 map { s/^\s*//s; s/\s*$/\n/s; $_; }
33                 split /\n\n\b/, <LOG>
34                 ];
35         close LOG;
36 }
37
38 # Merge changelogs.
39 # If there are entries for the same version in multiple changelogs,
40 # take the entry from the last changelog.
41 while ( @logs >= 2 ) {
42         my (@entries,@vers,$index);
43         while ( @{$logs[0]} > 0 && @{$logs[1]} > 0 )  {
44                 if ( $logs[0]->[0] eq $logs[1]->[0] ) {
45                         push @entries, $logs[1]->[0];
46                         shift @{$logs[0]};
47                         shift @{$logs[1]};
48                         next;
49                 }
50                 ($vers[0]) = $logs[0]->[0] =~ /^[^\n()]+ [(]([^()]+)[)]/s;
51                 ($vers[1]) = $logs[1]->[0] =~ /^[^\n()]+ [(]([^()]+)[)]/s;
52                 if ( defined $vers[0] && defined $vers[1] ) {
53                         if ( $vers[0] eq $vers[1] ) {
54                                 push @entries, $logs[1]->[0];
55                                 shift @{$logs[0]};
56                                 shift @{$logs[1]};
57                                 next;
58                         }
59                         my $status = system
60                                 'dpkg',
61                                 '--compare-versions',
62                                 $vers[0], 'gt', $vers[1];
63                         $status == 0 || $status == 1 << 8 || die;
64                         $index = $status == 0 ? 0 : 1;
65                 }
66                 elsif ( defined $vers[0] ) {
67                         $index = 0;
68                 }
69                 elsif ( defined $vers[1] ) {
70                         $index = 1;
71                 }
72                 else {
73                         last;
74                 }
75                 push @entries, shift @{$logs[$index]};
76         }
77         push @entries, @{$logs[0]}, @{$logs[1]};
78         splice @logs, 0, 2, \@entries;
79 }
80
81 # Print the merges changelog.
82 print join "\n", @{$logs[0]};