changelog.pl
3.86 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/perl
# changelog: update the changelog using your favorite visual editor
#
# When creating a new changelog section, if either of the environment
# variables CVS_EMAIL or EMAIL is set, changelog will use this as the
# uploader's email address (with the former taking precedence), and if
# CVS_FULLNAME is set, it will use this as the uploader's full name.
# Otherwise, it will just copy the values from the previous changelog
# entry.
#
# Originally by Christoph Lameter <clameter@debian.org>
# Modified extensively by Julian Gilbey <jdg@debian.org>
# Now a changelog script for GNU projects
# Sean 'Shaleh' Perry <shaleh@debian.org>
#
# Copyright 1999 by Julian Gilbey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use 5.003; # We're using function prototypes
use Getopt::Std;
use File::Copy;
use Cwd;
# Predeclare functions
sub fatal($);
my $progname;
($progname=$0) =~ s|.*/||;
sub usage {
print <<EOF
Usage: $progname [-h] [changelog entry]
Options:
-h Display this help message and exit
EOF
}
# Look for the changelog
if (! -e "ChangeLog")
{
die("Cannot find ChangeLog anywhere! " .
"Are you in the source code tree?");
}
if ( -e "ChangeLog.dch" ) {
die("The backup file ChangeLog.dch already exists --\n" .
"please move it before trying again");
} else {
$tmpchk=1;
}
sub BEGIN {
# Initialise the variable
$tmpchk=0;
}
sub END {
unlink "ChangeLog.dch" or
warn "Could not remove ChangeLog.dch"
if $tmpchk;
}
open S, "ChangeLog" or fatal "Cannot open ChangeLog:" . " $!";
open O, ">ChangeLog.dch"
or fatal "Cannot write to temporary file:" . " $!";
getopts('h')
or die sprintf
("Usage: %s [-h] [changelog entry]\n", $progname);
if ($opt_h) { usage(); exit(0); }
# Get a possible changelog entry from the command line
$SAVETEXT=$TEXT="@ARGV";
# Get the date
chomp($DATE=`date +%Y-%m-%d`);
$MAINTAINER = $ENV{'CVS_FULLNAME'} || $MAINTAINER;
if ($MAINTAINER eq '') {
fatal "Could not figure out maintainer's name:" . " $!";
}
$EMAIL = $ENV{'CVS_EMAIL'} || $ENV{'EMAIL'} || $EMAIL;
if ($EMAIL eq '') {
fatal "Could not figure out maintainer's email address:" . " $!";
}
print O "$DATE $MAINTAINER <$EMAIL>\n\n";
if ($TEXT) { write O } else { print O "\t* \n\n"; $line=3; }
# Rewind the current changelog to the beginning of the file
seek S,0,0 or fatal "Couldn't rewind ChangeLog:" . " $!";
# Copy the rest of the changelog file to new one
while (<S>) { print O; }
close S or fatal "Error closing ChangeLog:" . " $!";
close O or fatal "Error closing temporary ChangeLog:" . " $!";
# Now Run the Editor
if (! $SAVETEXT) {
$EDITOR=$ENV{"EDITOR"} || $ENV{"VISUAL"} || '/usr/bin/editor';
system("$EDITOR +$line ChangeLog.dch") / 256 == 0 or
fatal "Error editing the ChangeLog:" . " $!";
}
copy("ChangeLog.dch","ChangeLog") or
fatal "Couldn't replace ChangeLog with new ChangeLog:" . " $!";
# Format for standard ChangeLogs
format O =
* ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$TEXT
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$TEXT
.
sub fatal($) {
my ($pack,$file,$line);
($pack,$file,$line) = caller();
(my $msg = sprintf("%s: fatal error at line %d:\n",
$progname, $line) . "@_\n") =~ tr/\0//d;
$msg =~ s/\n\n$/\n/;
die $msg;
}