Fix syntax error in SmokeTest.java
[xapian.git] / xapian-maintainer-tools / changelog-to-news
blob5e0d9756fb7573292877b8d8162e5be77adb1745
1 #!/usr/bin/perl -w
2 # Copyright (c) Olly Betts 2010,2011,2012
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
20 # IN THE SOFTWARE.
21 use strict;
22 use POSIX;
24 my $vcs;
25 if (-d '.svn') {
26 $vcs = 'svn';
27 } else {
28 $vcs = 'git';
29 open CL, '<', 'ChangeLog' or die "Can't find 'ChangeLog' in current directory: $!\n";
30 my $cl_head = <CL>;
31 $vcs = 'gitlog' if $cl_head !~ /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) /;
33 my $new_version;
34 my $date = strftime("%Y-%m-%d", gmtime());
35 open NEWS, '<', 'NEWS' or die "Can't find 'NEWS' in current directory: $!\n";
36 my $news = <NEWS>;
37 my $rev1;
38 if ($news =~ /^(?:up *to:)? *(\d+|[[:xdigit:]]{7,})\b/i) {
39 # Partly updated already.
40 if ($vcs eq 'svn') {
41 $rev1 = $1 + 1;
42 } else {
43 $rev1 = $1;
45 # Discard that line...
46 $news = undef;
47 } elsif ($news =~ /^(?:Changes in|\S+) (\d[\d\.]*\.)(\d+) \(/) {
48 # No updates since the last release.
49 my $last_release = "$1$2";
50 $new_version = $1.($2+1);
51 print "Finding changes since release '$last_release'.\n";
52 if (-d '.svn') {
53 open SVNINFO, "svn info|" or die $!;
54 my $svnroot;
55 while (<SVNINFO>) {
56 if (s/^Repository Root: //) {
57 chomp;
58 $svnroot = $_;
59 last;
62 if (!defined $svnroot) {
63 die "svn info didn't tell us the repo root!\n";
65 close SVNINFO;
66 open SVNLOG, "svn log --limit=1 \Q$svnroot\E/tags/\Q$last_release\E|" or die $!;
67 my $line = <SVNLOG>;
68 if (!defined $line || $line !~ /^-+$/) {
69 $last_release =~ y/./_/;
70 open SVNLOG, "svn log --limit=1 \Q$svnroot\E/tags/v\Q$last_release\E|" or die $!;
71 $line = <SVNLOG>;
72 if (!defined $line || $line !~ /^-+$/) {
73 die "Unexpected output from svn log.\n";
76 $line = <SVNLOG>;
77 if ($line !~ /^r(\d+) \|/) {
78 die "Unexpected output from svn log.\n";
80 $rev1 = $1;
81 } else {
82 # git
83 $rev1 = "v$last_release";
85 } else {
86 die "Can't find revision in NEWS\n";
89 if ($vcs eq 'svn') {
90 open BLAME, "svn blame -r$rev1:HEAD ChangeLog 2>/dev/null|" or die $!;
91 } elsif ($vcs eq 'git') {
92 open BLAME, "git blame $rev1.. ChangeLog 2>/dev/null|" or die $!;
93 } else {
94 open BLAME, "git log $rev1.. -- . 2>/dev/null|" or die $!;
97 open NEWSTMP, '>', 'NEWS~' or die $!;
99 my $lines = 0;
100 my $prefix = "";
101 while (<BLAME>) {
102 if ($lines == 0) {
103 if ($vcs eq 'svn') {
104 print NEWSTMP;
105 } elsif ($vcs eq 'git') {
106 print NEWSTMP;
107 } else {
108 if (/ ([0-9a-f]+)/) {
109 print NEWSTMP "up to: $1\n\n";
113 if ($vcs eq 'svn') {
114 if (!s/^( *(\d+) +(\S+) )//) {
115 last if (/^ *-/);
116 } else {
117 if ($1 ne $prefix) {
118 $prefix = $1;
119 $_ = $prefix . $_;
120 print NEWSTMP "\n";
121 } else {
122 next if $_ eq "\n";
125 } elsif ($vcs eq 'git') {
126 next if /^\^/;
127 if (s/^([[:xdigit:]]+.*?) +\d+\) //) {
128 my $p = $1 . ")\n";
129 if ($p ne $prefix) {
130 $prefix = $p;
131 $_ = $prefix . $_;
132 print NEWSTMP "\n";
133 } else {
134 next if $_ eq "\n";
137 } else {
138 # next if /^\^/;
139 # if (s/^([[:xdigit:]]+.*?) +\d+\) //) {
140 # my $p = $1 . ")\n";
141 # if ($p ne $prefix) {
142 # $prefix = $p;
143 # $_ = $prefix . $_;
144 # print NEWSTMP "\n";
145 # } else {
146 # next if $_ eq "\n";
150 print NEWSTMP;
151 ++$lines;
153 close BLAME;
154 if ($lines == 0) {
155 close NEWSTMP;
156 unlink 'NEWS~';
157 print "No ChangeLog entries since the last update to NEWS.\n";
158 exit 0;
161 print NEWSTMP "\n";
162 if (defined $new_version) {
163 if (open NEWSSKEL, '<', 'NEWS.SKELETON') {
164 while (<NEWSSKEL>) {
165 s/\@VERSION\@/$new_version/g;
166 s/\@DATE\@/$date/g;
167 print NEWSTMP;
169 close NEWSSKEL;
172 print NEWSTMP $news if defined $news;
173 while (<NEWS>) {
174 if (!defined $new_version) {
175 if (s/^([A-Za-z][-\w]* (\d+(?:\.\d+)+) \()\d{4}-\d\d-\d\d(\):)$/$1$date$3/) {
176 $new_version = $2;
179 print NEWSTMP;
181 close NEWS;
182 close NEWSTMP or die $!;
183 rename 'NEWS~', 'NEWS' or die $!;