2 # mergechangelogs -- Tool to merge Debian changelogs
4 # Copyright (C) 2006 Nokia
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
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.
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,
28 foreach my $file ( @ARGV ) {
30 open LOG,'<',$file or die;
32 map { s/^\s*//s; s/\s*$/\n/s; $_; }
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];
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];
62 $vers[0], 'gt', $vers[1];
63 $status == 0 || $status == 1 << 8 || die;
64 $index = $status == 0 ? 0 : 1;
66 elsif ( defined $vers[0] ) {
69 elsif ( defined $vers[1] ) {
75 push @entries, shift @{$logs[$index]};
77 push @entries, @{$logs[0]}, @{$logs[1]};
78 splice @logs, 0, 2, \@entries;
81 # Print the merges changelog.
82 print join "\n", @{$logs[0]};