chiark / gitweb /
test suite: lib-reprepro: Add a couple of comments
[dgit.git] / tests / tstunt / dpkg-parsechangelog
1 #!/usr/bin/perl -w
2 #
3 # In an example:
4 #
5 # $ time dpkg-parsechangelog >/dev/null
6 #
7 # real    0m0.712s
8 # user    0m0.656s
9 # sys     0m0.048s
10 # $ time ~/things/Dgit/dgit/tests/tstunt/dpkg-parsechangelog >/dev/null
11 #
12 # real    0m0.016s
13 # user    0m0.000s
14 # sys     0m0.012s
15 # $
16
17 $SIG{__WARN__} = sub { die $_[0]; }; # no use of system, so we avoid #793471
18
19 my $infile = "debian/changelog";
20
21 #print STDERR ">@ARGV<\n";
22
23 my @orgargv = @ARGV;
24
25 if (@ARGV && $ARGV[0] =~ s/^-l//) {
26     $infile = shift @ARGV;
27 }
28
29 if (@ARGV) {
30     my $strip = $0;
31     $strip =~ s#/[^/]+$## or die "$0 ?";
32     foreach my $k (qw(PATH PERLLIB)) {
33         my @opath = defined $ENV{$k} ? split /\:/, $ENV{$k} : ();
34         my @npath = grep { $_ ne $strip } @opath;
35         @npath != @opath  or die "$0 $k ".($ENV{$k}//"(undef)")." ?";
36         $ENV{$k} = join ':', @npath;
37         delete $ENV{$k} if !@npath;
38     }
39     die if $ENV{'DGIT_NO_TSTUNT_CLPARSE'}++;
40     exec 'dpkg-parsechangelog', @orgargv;
41 }
42
43 use strict;
44 open C, $infile or die $!;
45
46 $!=0; $_ = <C>;
47 m/^(\S+) \(([^()]+)\) (\S+)\; urgency=(\S+)$/ or die "$!, $_ ?";
48 print <<END or die $!;
49 Source: $1
50 Version: $2
51 Distribution: $3
52 Urgency: $4
53 Changes: 
54  $&
55 END
56
57 my $blanks = 0;
58 for (;;) {
59     $!=0; $_ = <C>;
60     if (m/^ -- ([^<>]+\<\S+\>)  (\w[^<>]+\w)$/) {
61         print <<END or die $!;
62 Maintainer: $1
63 Date: $2
64 END
65         print "Timestamp: " or die $!;
66         exec qw(date +%s -d), $2; die $!;
67     } elsif (m/^ --\s*$/) {
68         last;
69     } elsif (!m/\S/) {
70         $blanks++;
71     } elsif (m/^  .*\n/) {
72         print " .\n" x $blanks or die $!;
73         $blanks=0;
74         print " $_" or die $!;
75     } else {
76         die "$!, $_ ?";
77     }
78 }