1#! /bin/sh
2# rcsfreeze - assign a symbolic revision number to a configuration of RCS files
3#
4# Copyright (C) 2010-2020 Thien-Thi Nguyen
5#
6# This file is part of GNU RCS.
7#
8# GNU RCS is free software: you can redistribute it and/or modify it
9# under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# GNU RCS is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty
15# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16# See the GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20##
21# Usage: rcsfreeze [symbolic-name]
22#
23#       The idea is to run rcsfreeze each time a new version is checked
24#       in. A unique symbolic revision number (C_[number], where number
25#       is increased each time rcsfreeze is run) is then assigned to the most
26#       recent revision of each RCS file of the main trunk.
27#
28#       If the command is invoked with an argument, then this
29#       argument is used as the symbolic name to freeze a configuration.
30#       The unique identifier is still generated
31#       and is listed in the log file but it will not appear as
32#       part of the symbolic revision name in the actual RCS file.
33#
34#       A log message is requested from the user which is saved for future
35#       references.
36#
37#       The shell script works only on all RCS files at one time.
38#       It is important that all changed files are checked in (there are
39#       no precautions against any error in this respect).
40#       file names:
41#       {RCS/}.rcsfreeze.ver	version number
42#       {RCS/}.rscfreeze.log	log messages, most recent first
43##
44version='rcsfreeze (GNU RCS) @PACKAGE_VERSION@
45Copyright (C) 2010-2020 Thien-Thi Nguyen
46Copyright (C) 1990-1995 Paul Eggert
47License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
48This is free software: you are free to change and redistribute it.
49There is NO WARRANTY, to the extent permitted by law.
50
51Written by Stephan v. Bechtolsheim.'
52
53usage ()
54{
55    sed '/^##/,/^##/!d;/^##/d;s/^# //g;s/^#$//g' $0
56}
57
58if [ x"$1" = x--help ] ; then usage ; exit 0 ; fi
59if [ x"$1" = x--version ] ; then echo "$version" ; exit 0 ; fi
60
61PATH=/usr/local/bin:/bin:/usr/bin:/usr/ucb:$PATH
62export PATH
63
64DATE=`date` || exit
65# Check whether we have an RCS subdirectory, so we can have the right
66# prefix for our paths.
67if test -d RCS
68then RCSDIR=RCS/ EXT=
69else RCSDIR= EXT=,v
70fi
71
72# Version number stuff, log message file
73VERSIONFILE=${RCSDIR}.rcsfreeze.ver
74LOGFILE=${RCSDIR}.rcsfreeze.log
75# Initialize, rcsfreeze never run before in the current directory
76test -r $VERSIONFILE || { echo 0 >$VERSIONFILE && >>$LOGFILE; } || exit
77
78# Get Version number, increase it, write back to file.
79VERSIONNUMBER=`cat $VERSIONFILE` &&
80VERSIONNUMBER=`expr $VERSIONNUMBER + 1` &&
81echo $VERSIONNUMBER >$VERSIONFILE || exit
82
83# Symbolic Revision Number
84SYMREV=C_$VERSIONNUMBER
85# Allow the user to give a meaningful symbolic name to the revision.
86SYMREVNAME=${1-$SYMREV}
87echo >&2 "rcsfreeze: symbolic revision number computed: \"${SYMREV}\"
88rcsfreeze: symbolic revision number used:     \"${SYMREVNAME}\"
89rcsfreeze: the two differ only when rcsfreeze invoked with argument
90rcsfreeze: give log message, summarizing changes (end with EOF or single '.')" \
91	|| exit
92
93# Stamp the logfile. Because we order the logfile the most recent
94# first we will have to save everything right now in a temporary file.
95TMPLOG=`mktemp -t` || exit
96trap 'rm -f $TMPLOG; exit 1' 1 2 13 15
97# Now ask for a log message, continously add to the log file
98(
99	echo "Version: $SYMREVNAME($SYMREV), Date: $DATE
100-----------" || exit
101	while read MESS
102	do
103		case $MESS in
104		.) break
105		esac
106		echo "	$MESS" || exit
107	done
108	echo "-----------
109" &&
110	cat $LOGFILE
111) >$TMPLOG &&
112
113# combine old and new logfiles
114cp $TMPLOG $LOGFILE &&
115rm -f $TMPLOG &&
116
117# Now the real work begins by assigning a symbolic revision number
118# to each rcs file.  Take the most recent version on the default branch.
119
120# If there are any .*,v files, throw them in too.
121# But ignore RCS/.* files that do not end in ,v.
122DOTFILES=
123for DOTFILE in ${RCSDIR}.*,v
124do
125	if test -f "$DOTFILE"
126	then
127		DOTFILES="${RCSDIR}.*,v"
128		break
129	fi
130done
131
132exec rcs -q -n$SYMREVNAME: ${RCSDIR}*$EXT $DOTFILES
133