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};
28 if ($ARGV[0] eq '--test') {
33 if ($ARGV[0] eq '--type') {
38 if (@ARGV > 1 && $ARGV[0] eq '--target') {
40 $target = shift @ARGV;
46 if (@ARGV == 2 && $ARGV[0] eq '--file') {
47 die("bad --file arg\n") unless $ARGV[1] =~ /^(.*)\/([^\/]+)$/;
48 my ($dir, $file) = ($1, $2);
49 $file =~ s/\.(?:spec|dsc)$//;
50 opendir(D, $dir) || die("$dir: $!\n");
51 my @changes = grep {/\.changes$/} readdir(D);
53 @changes = sort {length($a) <=> length($b) || $a cmp $b} @changes;
54 exit(1) unless @changes; # nothing to do
57 my @c = grep {/\Q$file\E/} @changes;
62 last unless $file =~ s/[-.][^-.]*$//;
65 @ARGV = ("$dir/$changes[0]");
72 die("bad changelog heading\n") unless /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
78 $dt =~ /([0-9][0-9][0-9][0-9])/;
81 if (!defined($zone) && $dt =~ /\s([a-z]{3,4})(dst)?\s[0-9]{4}/) {
83 $zone = tz_offset($1);
84 $zone += 3600 if defined($zone) && $dst;
86 my $tdt = str2time($dt);
90 if ($dt =~ /([a-z]{3})\s+([a-z]{3})/) {
91 $tdt = str2time("$1 $2 $day $year");
95 if ($dt =~ /([a-z]{3})/) {
96 $tdt = str2time("$1 $day $year");
100 $tdt = str2time("$year-1-1");
102 $tdt += 12 * 3600 unless $dt =~ /\d:\d/; # 12:00 if not specified
103 $tdt += ($zone || 0);
108 last if /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
109 next if (/^--------------/);
110 next if (/^========================/);
113 s/^\s*-/-/ if $ok == 1; # obsolete?
117 s/^\s*/ / unless s/^ \s*/ /;
122 return ($_, $tdt, $dline, $who, $change);
128 die("bad line: $_\n") unless /^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/;
131 my $distribution = $3;
134 my $changes = "- version $version\n";
140 die("bad maintainer line\n") unless /^ \-\- (.* <.*>) (.*)$/;
145 die("bad change details line: $_\n") unless s/^ //;
147 s/\s*\(closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*\)//i;
152 die("no maintainer line in last entry\n") unless defined $date;
153 if (!defined($zone) && ($date =~ /([-+])(\d\d)(\d\d)$/)) {
154 $zone = 60 * ($3 + 60 * $2);
155 $zone = -$zone if $1 eq '-';
157 my $tdt = str2time($date);
158 return ('', $tdt, $_, $who, $changes);
165 next if (/^--------------/);
166 next if (/^========================/);
167 if (/^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/) {
170 } elsif (/^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/) {
173 die("unknown changelog format\n");
177 exit(0) unless $format;
184 if ($target eq $format) {
192 die("don't know how to convert changelog to format '$target'\n") if $target ne 'rpm';
194 my ($lastt, $t, $dline, $who, $changes);
202 if ($format eq 'suse') {
203 ($_, $t, $dline, $who, $changes) = parse_suse($_);
204 } elsif ($format eq 'debian') {
205 ($_, $t, $dline, $who, $changes) = parse_debian($_);
207 if (defined($lastt) && $lastt < $t) {
208 die("changes file not incremental: $dline\n") if $test;
209 warn("changes file not incremental: $dline\n");
213 # silly rpm can't hande dates < 1997, so we fold everything to
215 @gm = (0, 0, 0, 2, 0, 97, 4) if $gm[5] < 97 || ($gm[5] == 97 && $gm[4] == 0 && $gm[3] <= 1);
216 printf("* %s %s %2d %4d %s\n", $wday[$gm[6]], $mon[$gm[4]], $gm[3], $gm[5] + 1900, $who);
217 $changes =~ s/%/%%/g;
218 $changes =~ s/^(\s*)(\#\d*)/$1\[$2\]/mg;
219 $changes =~ s/^\*/ */mg;