2 # Copyright (c) Olly Betts 2010-2021
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to
6 # deal in the Software without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 if (open CL
, '<', 'ChangeLog') {
32 $vcs = 'git' if $cl_head =~ /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) /;
36 my $date = strftime
("%Y-%m-%d", gmtime());
37 open NEWS
, '<', 'NEWS' or die "Can't find 'NEWS' in current directory: $!\n";
40 if ($news =~ /^(?:up *to:?) *([[:xdigit:]]{7,}|\d+)\b/i) {
41 # Partly updated already.
47 # Discard that line...
49 } elsif ($news =~ /^(?:Changes in|\S+) (\d[\d\.]*\.)(\d+) \(/) {
50 # No updates since the last release.
51 my $last_release = "$1$2";
52 $new_version = $1.($2+1);
53 print "Finding changes since release '$last_release'.\n";
55 open SVNINFO
, "svn info|" or die $!;
58 if (s/^Repository Root: //) {
64 if (!defined $svnroot) {
65 die "svn info didn't tell us the repo root!\n";
68 open SVNLOG
, "svn log --limit=1 \Q$svnroot\E/tags/\Q$last_release\E|" or die $!;
70 if (!defined $line || $line !~ /^-+$/) {
71 $last_release =~ y/./_/;
72 open SVNLOG
, "svn log --limit=1 \Q$svnroot\E/tags/v\Q$last_release\E|" or die $!;
74 if (!defined $line || $line !~ /^-+$/) {
75 die "Unexpected output from svn log.\n";
79 if ($line !~ /^r(\d+) \|/) {
80 die "Unexpected output from svn log.\n";
85 $rev1 = "v$last_release";
86 if (`git tag -l \Q$rev1\E` eq '' && `git tag -l \Q$last_release\E` ne '') {
87 $rev1 = $last_release;
91 die "Can't find revision in NEWS\n";
95 open BLAME
, "svn blame -r$rev1:HEAD ChangeLog 2>/dev/null|" or die $!;
96 } elsif ($vcs eq 'git') {
97 open BLAME
, "git blame $rev1.. ChangeLog 2>/dev/null|" or die $!;
99 open BLAME
, "git log $rev1.. -- . 2>/dev/null|" or die $!;
102 open NEWSTMP
, '>', 'NEWS~' or die $!;
110 } elsif ($vcs eq 'git') {
113 if (/ ([0-9a-f]+)/) {
114 print NEWSTMP
"up to: $1\n\n";
119 if (!s/^( *(\d+) +(\S+) )//) {
130 } elsif ($vcs eq 'git') {
132 if (s/^([[:xdigit:]]+.*?) +\d+\) //) {
144 # if (s/^([[:xdigit:]]+.*?) +\d+\) //) {
145 # my $p = $1 . ")\n";
146 # if ($p ne $prefix) {
149 # print NEWSTMP "\n";
151 # next if $_ eq "\n";
163 print "No ChangeLog entries since the last update to NEWS.\n";
168 if (defined $new_version) {
169 if (open NEWSSKEL
, '<', 'NEWS.SKELETON') {
171 s/\@VERSION\@/$new_version/g;
178 print NEWSTMP
$news if defined $news;
180 if (!defined $new_version) {
181 # Handle placeholder date like ????-??-??.
182 if (/^([A-Za-z][-\w]* (\d+(?:\.\d+)+) \()(....-..-..)(\):)$/) {
187 if ($old_date =~ /^\d{4}-\d\d-\d\d$/) {
188 $_ = "$pre$date$post";
195 close NEWSTMP
or die $!;
196 rename 'NEWS~', 'NEWS' or die $!;