4 # Convert a SUSE or Debian changelog file to rpm format
8 unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
16 my @wday = qw{Sun Mon Tue Wed Thu Fri Sat};
17 my @mon = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
27 if ($ARGV[0] eq '--test') {
32 if ($ARGV[0] eq '--type') {
37 if (@ARGV > 1 && $ARGV[0] eq '--target') {
39 $target = shift @ARGV;
45 if (@ARGV == 2 && $ARGV[0] eq '--file') {
46 die("bad --file arg\n") unless $ARGV[1] =~ /^(.*)\/([^\/]+)$/;
47 my ($dir, $file) = ($1, $2);
48 $file =~ s/\.(?:spec|dsc)$//;
49 opendir(D, $dir) || die("$dir: $!\n");
50 my @changes = grep {/\.changes$/} readdir(D);
52 @changes = sort {length($a) <=> length($b) || $a cmp $b} @changes;
53 exit(1) unless @changes; # nothing to do
56 my @c = grep {/\Q$file\E/} @changes;
61 last unless $file =~ s/[-.][^-.]*$//;
64 @ARGV = ("$dir/$changes[0]");
71 die("bad changelog heading\n") unless /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
77 $dt =~ /([0-9][0-9][0-9][0-9])/;
80 if (!defined($zone) && $dt =~ /\s([a-z]{3,4})(dst)?\s[0-9]{4}/) {
82 $zone = tz_offset($1);
83 $zone += 3600 if defined($zone) && $dst;
85 my $tdt = str2time($dt);
89 if ($dt =~ /([a-z]{3})\s+([a-z]{3})/) {
90 $tdt = str2time("$1 $2 $day $year");
94 if ($dt =~ /([a-z]{3})/) {
95 $tdt = str2time("$1 $day $year");
99 $tdt = str2time("$year-1-1");
101 $tdt += 12 * 3600 unless $dt =~ /\d:\d/; # 12:00 if not specified
102 $tdt += ($zone || 0);
107 last if /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
108 next if (/^--------------/);
109 next if (/^========================/);
112 s/^\s*-/-/ if $ok == 1; # obsolete?
116 s/^\s*/ / unless s/^ \s*/ /;
121 return ($_, $tdt, $dline, $who, $change);
127 die("bad line: $_\n") unless /^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/;
130 my $distribution = $3;
133 my $changes = "- version $version\n";
139 die("bad maintainer line\n") unless /^ \-\- (.* <.*>) (.*)$/;
144 die("bad change details line: $_\n") unless s/^ //;
146 s/\s*\(closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*\)//i;
151 die("no maintainer line in last entry\n") unless defined $date;
152 if (!defined($zone) && ($date =~ /([-+])(\d\d)(\d\d)$/)) {
153 $zone = 60 * ($3 + 60 * $2);
154 $zone = -$zone if $1 eq '-';
156 my $tdt = str2time($date);
157 return ('', $tdt, $_, $who, $changes);
164 next if (/^--------------/);
165 next if (/^========================/);
166 if (/^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/) {
169 } elsif (/^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/) {
172 die("unknown changelog format\n");
176 exit(0) unless $format;
183 if ($target eq $format) {
191 die("don't know how to convert changelog to format '$target'\n") if $target ne 'rpm';
193 my ($lastt, $t, $dline, $who, $changes);
201 if ($format eq 'suse') {
202 ($_, $t, $dline, $who, $changes) = parse_suse($_);
203 } elsif ($format eq 'debian') {
204 ($_, $t, $dline, $who, $changes) = parse_debian($_);
206 if (defined($lastt) && $lastt < $t) {
207 die("changes file not incremental: $dline\n") if $test;
208 warn("changes file not incremental: $dline\n");
212 # silly rpm can't hande dates < 1997, so we fold everything to
214 @gm = (0, 0, 0, 2, 0, 97, 4) if $gm[5] < 97 || ($gm[5] == 97 && $gm[4] == 0 && $gm[3] <= 1);
215 printf("* %s %s %2d %4d %s\n", $wday[$gm[6]], $mon[$gm[4]], $gm[3], $gm[5] + 1900, $who);
216 $changes =~ s/%/%%/g;
217 $changes =~ s/^(\s*)%%(\S*)/$1\[%%$2\]/;
218 $changes =~ s/^(\s*)(\#\d*)/$1\[$2\]/mg;
219 $changes =~ s/^\*/ */mg;