Commit | Line | Data |
e7a78651 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings FATAL => 'all'; |
4 | |
5 | my $version = shift; |
6 | my @ymd = (gmtime)[5,4,3]; |
7 | $ymd[0] += 1900; |
8 | $ymd[1] += 1; |
9 | my $changes_line = sprintf "%s - %i-%02i-%02i\n", $version, @ymd; |
10 | |
11 | foreach my $changes (@ARGV) { |
12 | print "Adding $version heading to $changes.\n"; |
13 | open my $fh, '+<', $changes |
14 | or die "Can't open $changes: $!"; |
15 | my $content = ''; |
16 | my $done; |
17 | local $/ = $/; |
18 | while (<$fh>) { |
19 | if ($done) { |
20 | undef $/; |
21 | } |
22 | elsif (/^v?(\d+(?:\.\d+)*)(\s+|$)/) { |
23 | if ($1 eq $version) { |
24 | die "$changes already has an entry for $version!\n"; |
25 | } |
26 | else { |
27 | die "No changelog entries found before $1!\n"; |
28 | } |
29 | } |
30 | elsif (/^\s+[-*+#]/) { |
31 | $content .= $changes_line; |
32 | $done = 1; |
33 | } |
34 | $content .= $_; |
35 | } |
36 | |
37 | seek $fh, 0, 0; |
38 | truncate $fh, 0; |
39 | print { $fh } $content; |
40 | close $fh; |
41 | } |