3 # ucl - update changelog for subversion projects (perl version)
5 # Copyright (c) 2005-2010 by Ricardo Mones <ricardo@mones.org>
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 # and/or sell copies of the Software, and to permit persons to whom the
12 # Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
28 my $PROJECT = "clawsker"; # project name under trunk
29 my $REPO = "https://svn.mones.org/svn"; # repository base URL
30 my $CL = './ChangeLog'; # changelog file
31 my $VF = './VERSION'; # version file
32 my $SF = '.ucl.status'; # status file
33 my $PCL = '.ucl.prev'; # previous changelog
34 my @NOTFORRELEASE = ( "ucl" );
40 die "Invalid release version\n" unless (/^\d+\.\d+\.\d+$/);
41 my $namevers = "$PROJECT-$relnum";
42 my $sourceurl = "$REPO/trunk/$PROJECT";
43 my $targeturl = "$REPO/tags/$PROJECT/$namevers";
44 my $commitmsg = "'tag release $relnum'";
45 qx/svn cp $sourceurl $targeturl -m $commitmsg/;
48 sub tarball_from_release_tag {
51 die "Invalid release version\n" unless (/^\d+\.\d+\.\d+$/);
52 my $namevers = "$PROJECT-$relnum";
53 my $targeturl = "$REPO/tags/$PROJECT/$namevers";
54 qx/svn export $targeturl/;
55 foreach my $file (@NOTFORRELEASE) {
56 if (-f "$namevers/$file") {
57 unlink("$namevers/$file");
60 qx/tar czf $namevers.tar.gz $namevers/;
64 if (defined($ARGV[0])) {
67 die "Undefined release version\n" unless defined ($ARGV[1]);
69 die "Invalid release version\n" unless (/^\d+\.\d+\.\d+$/);
73 die "Undefined release version\n" unless defined ($ARGV[1]);
74 &tag_new_release ($ARGV[1]);
78 die "Undefined release version\n" unless defined ($ARGV[1]);
79 &tarball_from_release_tag ($ARGV[1]);
83 my $help = <<'ENDOFHELP'
85 ucl Update changelog for Subversion repository
89 -r x.y.z Update is for release version x.y.z
90 -t x.y.z Tags current trunk as release x.y.z on repository
91 -T x.y.z Makes x.y.z release tarball
98 die "Unknown option. Try -? for help\n";
103 sub get_changelog_date {
104 my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime();
107 $hour = ($hour < 10)? "0$hour": "$hour";
108 $min = ($min < 10)? "0$min": "$min";
109 $mon = ($mon < 10)? "0$mon": "$mon";
110 $mday = ($mday < 10)? "0$mday": "$mday";
111 return "$year-$mon-$mday $hour:$min";
115 # check we're in the right place
116 -e "$CL" or die "Oops, no ChangeLog here\n";
117 -e "$VF" or die "Oops, no VERSION here\n";
119 # parser VERSION file or $release argument
120 my ($major, $minor, $micro, $extra) = (undef, undef, undef, undef);
121 if (not defined ($release)) { # got number it from version file
130 if (/^(\d+)\.(\d+)\.(\d+)$/) {
131 ($major, $minor, $micro, $extra) = ($1, $2, $3, "");
133 if (/^(\d+)\.(\d+)\.(\d+)svn(\d+)$/) {
134 ($major, $minor, $micro, $extra) = ($1, $2, $3, $4);
136 # update directory to be sure we're at the last rev
137 $_ = qx/LANGUAGE=C svn up/;
138 my @updateout = split /\\n/;
139 # get last revision from repository
140 $_ = qx/LANGUAGE=C svn info | grep "Revision"/;
144 # calculate modifications
145 qx/svn status > $SF/;
150 if (/^MM?\s+(.*)$/) {
151 push (@modifs, "\t* $1");
153 if (/^AM?\s+(.*)$/) {
154 push (@modifs, "\t* $1\t\t**NEW**");
157 push (@modifs, "\t* $1\t\t**REMOVED**");
160 print "Info: not versioned: $1\n";
164 unlink ($SF); # remove the status file
165 # save previous changelog
167 # write new entry header
169 my $cldate = &get_changelog_date;
170 my $cluser = $ENV{USER};
171 my $clvers = "$major.$minor.$micro";
172 if ($release eq "") {
174 $clvers = ($clvers . "svn" . (1 + $lastrev));
177 # write new entry modifications
178 print NCL "$cldate $cluser $clvers\n\n";
179 foreach my $modif (@modifs) {
180 print NCL "$modif\n";
183 # and previous entries
185 while (<PCL>) { print NCL $_; }
188 # and keep a digest for checking
189 my $oldmd5 = qx/md5sum $CL | cut -f1 -d" "/;
191 my $editor = 'vim'; # (defined($ENV{DISPLAY}))? 'gvim -f': 'vim';
192 if (defined($ENV{EDITOR})) {
193 $editor = $ENV{EDITOR};
195 my @editor = ($editor, $CL);
198 my $newmd5 = qx/md5sum $CL | cut -f1 -d" "/;
199 if ($oldmd5 eq $newmd5) {
200 print "Unmodified ChangeLog, discarding changes.\n";
206 # update new version after changes
207 qx/echo $clvers > $VF/;