Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-maintainer-tools / changelog-to-news
blobfa00eeafafaf0f1a9117e3c5e31ce2289157a0a7
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';
30 my $new_version;
31 my $date = strftime("%Y-%m-%d", gmtime());
32 open NEWS, '<', 'NEWS' or die "Can't find 'NEWS' in current directory: $!\n";
33 my $news = <NEWS>;
34 my $rev1;
35 if ($news =~ /^(?:up *to:)? *(\d+|[[:xdigit:]]{7,})\b/i) {
36 # Partly updated already.
37 if ($vcs eq 'svn') {
38 $rev1 = $1 + 1;
39 } else {
40 $rev1 = $1;
42 # Discard that line...
43 $news = undef;
44 } elsif ($news =~ /^(?:Changes in|\S+) (\d[\d\.]*\.)(\d+) \(/) {
45 # No updates since the last release.
46 my $last_release = "$1$2";
47 $new_version = $1.($2+1);
48 print "Finding changes since release '$last_release'.\n";
49 if (-d '.svn') {
50 open SVNINFO, "svn info|" or die $!;
51 my $svnroot;
52 while (<SVNINFO>) {
53 if (s/^Repository Root: //) {
54 chomp;
55 $svnroot = $_;
56 last;
59 if (!defined $svnroot) {
60 die "svn info didn't tell us the repo root!\n";
62 close SVNINFO;
63 open SVNLOG, "svn log --limit=1 \Q$svnroot\E/tags/\Q$last_release\E|" or die $!;
64 my $line = <SVNLOG>;
65 if (!defined $line || $line !~ /^-+$/) {
66 $last_release =~ y/./_/;
67 open SVNLOG, "svn log --limit=1 \Q$svnroot\E/tags/v\Q$last_release\E|" or die $!;
68 $line = <SVNLOG>;
69 if (!defined $line || $line !~ /^-+$/) {
70 die "Unexpected output from svn log.\n";
73 $line = <SVNLOG>;
74 if ($line !~ /^r(\d+) \|/) {
75 die "Unexpected output from svn log.\n";
77 $rev1 = $1;
78 } else {
79 # git
80 $rev1 = $last_release;
82 } else {
83 die "Can't find revision in NEWS\n";
86 if ($vcs eq 'svn') {
87 open BLAME, "svn blame -r$rev1:HEAD ChangeLog 2>/dev/null|" or die $!;
88 } else {
89 open BLAME, "git blame $rev1.. ChangeLog 2>/dev/null|" or die $!;
92 open NEWSTMP, '>', 'NEWS~' or die $!;
94 my $lines = 0;
95 my $prefix = "";
96 while (<BLAME>) {
97 print NEWSTMP if $lines == 0;
98 if ($vcs eq 'svn') {
99 if (!s/^( *(\d+) +(\S+) )//) {
100 last if (/^ *-/);
101 } else {
102 if ($1 ne $prefix) {
103 $prefix = $1;
104 $_ = $prefix . $_;
105 print NEWSTMP "\n";
106 } else {
107 next if $_ eq "\n";
110 } else {
111 next if /^\^/;
112 if (s/^([[:xdigit:]]+.*?) +\d+\) //) {
113 my $p = $1 . ")\n";
114 if ($p ne $prefix) {
115 $prefix = $p;
116 $_ = $prefix . $_;
117 print NEWSTMP "\n";
118 } else {
119 next if $_ eq "\n";
123 print NEWSTMP;
124 ++$lines;
126 close BLAME;
127 if ($lines == 0) {
128 close NEWSTMP;
129 unlink 'NEWS~';
130 print "No ChangeLog entries since the last update to NEWS.\n";
131 exit 0;
134 print NEWSTMP "\n";
135 if (defined $new_version) {
136 if (open NEWSSKEL, '<', 'NEWS.SKELETON') {
137 while (<NEWSSKEL>) {
138 s/\@VERSION\@/$new_version/g;
139 s/\@DATE\@/$date/g;
140 print NEWSTMP;
142 close NEWSSKEL;
145 print NEWSTMP $news if defined $news;
146 while (<NEWS>) {
147 if (!defined $new_version) {
148 if (s/^([A-Za-z][-\w]* (\d+(?:\.\d+)+) \()\d{4}-\d\d-\d\d(\):)$/$1$date$3/) {
149 $new_version = $2;
152 print NEWSTMP;
154 close NEWS;
155 close NEWSTMP or die $!;
156 rename 'NEWS~', 'NEWS' or die $!;