summaryrefslogtreecommitdiff
path: root/tests/tstunt/dpkg-parsechangelog
blob: 2e0360da112c2793532d752ff1bfc6944d782490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w
#
# In an example:
#
# $ time dpkg-parsechangelog >/dev/null
#
# real    0m0.712s
# user    0m0.656s
# sys     0m0.048s
# $ time ~/things/Dgit/dgit/tests/tstunt/dpkg-parsechangelog >/dev/null
#
# real    0m0.016s
# user    0m0.000s
# sys     0m0.012s
# $

die if @ARGV;

use strict;
open C, "debian/changelog" or die $!;

$!=0; $_ = <C>;
m/^(\S+) \(([^()]+)\) (\S+)\; urgency=(\S+)$/ or die "$!, $_ ?";
print <<END or die $!;
Source: $1
Version: $2
Distribution: $3
Urgency: $4
Changes: 
 $&
END

my $blanks = 0;
for (;;) {
    $!=0; $_ = <C>;
    if (m/^ -- ([^<>]+\<\S+\>)  (\w[^<>]+\w)$/) {
	print <<END or die $!;
Maintainer: $1
Date: $2
END
        last;
    } elsif (m/^ --\s*$/) {
	last;
    } elsif (!m/\S/) {
	$blanks++;
    } elsif (m/^  .*\n/) {
	print " .\n" x $blanks or die $!;
	$blanks=0;
	print " $_" or die $!;
    } else {
	die "$!, $_ ?";
    }
}