xref: /openbsd/gnu/usr.bin/cvs/contrib/rcs-to-cvs.sh (revision 780d15df)
1#! /bin/sh
2#
3# Based on the CVS 1.0 checkin csh script.
4# Contributed by Per Cederqvist <ceder@signum.se>.
5# Rewritten in sh by David MacKenzie <djm@cygnus.com>.
6#
7#   Copyright (c) 1989, Brian Berliner
8#
9#   You may distribute under the terms of the GNU General Public License.
10#
11#############################################################################
12#
13# Check in sources that previously were under RCS or no source control system.
14#
15# The repository is the directory where the sources should be deposited.
16#
17# Traverses the current directory, ensuring that an
18# identical directory structure exists in the repository directory.  It
19# then checks the files in in the following manner:
20#
21#		1) If the file doesn't yet exist, check it in as revision 1.1
22#
23# The script also is somewhat verbose in letting the user know what is
24# going on.  It prints a diagnostic when it creates a new file, or updates
25# a file that has been modified on the trunk.
26#
27# Bugs: doesn't put the files in branch 1.1.1
28#       doesn't put in release and vendor tags
29#
30#############################################################################
31
32usage="Usage: rcs-to-cvs [-v] [-m message] [-f message_file] repository"
33vbose=0
34message=""
35if [ -d /var/tmp ]; then message_file=/var/tmp/checkin.$$; else message_file=/usr/tmp/checkin.$$; fi
36got_one=0
37
38if [ $# -lt 1 ]; then
39    echo "$usage" >&2
40    exit 1
41fi
42
43while [ $# -ne 0 ]; do
44    case "$1" in
45        -v)
46            vbose=1
47	    ;;
48	-m)
49	    shift
50	    echo $1 > $message_file
51	    got_one=1
52	    ;;
53	-f)
54	    shift
55	    message_file=$1
56	    got_one=2
57	    ;;
58	*)
59	    break
60    esac
61    shift
62done
63
64if [ $# -lt 1 ]; then
65    echo "$usage" >&2
66    exit 1
67fi
68
69repository=$1
70shift
71
72if [ -z "$CVSROOT" ]; then
73    echo "Please the environmental variable CVSROOT to the root" >&2
74    echo "	of the tree you wish to update" >&2
75    exit 1
76fi
77
78if [ $got_one -eq 0 ]; then
79    echo "Please Edit this file to contain the RCS log information" >$message_file
80    echo "to be associated with this directory (please remove these lines)">>$message_file
81    ${EDITOR-vi} $message_file
82    got_one=1
83fi
84
85# Ya gotta share.
86umask 0
87
88update_dir=${CVSROOT}/${repository}
89[ ! -d ${update_dir} ] && mkdir $update_dir
90
91if [ -d SCCS ]; then
92    echo SCCS files detected! >&2
93    exit 1
94fi
95if [ -d RCS ]; then
96    co RCS/*
97fi
98
99for name in * .[a-zA-Z0-9]*
100do
101    case "$name" in
102    RCS | *~ | \* | .\[a-zA-Z0-9\]\* ) continue ;;
103    esac
104    echo $name
105    if [ $vbose -ne 0 ]; then
106	echo "Updating ${repository}/${name}"
107    fi
108    if [ -d "$name" ]; then
109	if [ ! -d "${update_dir}/${name}" ]; then
110	    echo "WARNING: Creating new directory ${repository}/${name}"
111	    mkdir "${update_dir}/${name}"
112	    if [ $? -ne 0 ]; then
113		echo "ERROR: mkdir failed - aborting" >&2
114		exit 1
115	    fi
116	fi
117	cd "$name"
118	if [ $? -ne 0 ]; then
119	    echo "ERROR: Couldn\'t cd to $name - aborting" >&2
120	    exit 1
121	fi
122	if [ $vbose -ne 0 ]; then
123	    $0 -v -f $message_file "${repository}/${name}"
124	else
125	    $0 -f $message_file "${repository}/${name}"
126	fi
127	if [ $? -ne 0 ]; then
128	    exit 1
129	fi
130	cd ..
131    else	# if not directory
132	if [ ! -f "$name" ]; then
133	    echo "WARNING: $name is neither a regular file"
134	    echo "	   nor a directory - ignored"
135	    continue
136	fi
137	file="${update_dir}/${name},v"
138	comment=""
139	if grep -s '\$Log.*\$' "${name}"; then # If $Log keyword
140	    myext=`echo $name | sed 's,.*\.,,'`
141	    [ "$myext" = "$name" ] && myext=
142	    case "$myext" in
143		c | csh | e | f | h | l | mac | me | mm | ms | p | r | red | s | sh | sl | cl | ml | el | tex | y | ye | yr | "" )
144		;;
145
146		* )
147		echo "For file ${file}:"
148		grep '\$Log.*\$' "${name}"
149		echo -n "Please insert a comment leader for file ${name} > "
150		read comment
151		;;
152	    esac
153	fi
154	if [ ! -f "$file" ]; then	# If not exists in repository
155	    if [ ! -f "${update_dir}/Attic/${name},v" ]; then
156	        echo "WARNING: Creating new file ${repository}/${name}"
157		if [ -f RCS/"${name}",v ]; then
158			echo "MSG: Copying old rcs file."
159			cp RCS/"${name}",v "$file"
160		else
161   		    if [ -n "${comment}" ]; then
162		        rcs -q -i -c"${comment}" -t${message_file} -m'.' "$file"
163		    fi
164	            ci -q -u1.1 -t${message_file} -m'.' "$file"
165	            if [ $? -ne 0 ]; then
166		        echo "ERROR: Initial check-in of $file failed - aborting" >&2
167		        exit 1
168	            fi
169		fi
170	    else
171		file="${update_dir}/Attic/${name},v"
172		echo "WARNING: IGNORED: ${repository}/Attic/${name}"
173		continue
174	    fi
175	else	# File existed
176	    echo "ERROR: File exists in repository: Ignored: $file"
177	    continue
178	fi
179    fi
180done
181
182[ $got_one -eq 1 ] && rm -f $message_file
183
184exit 0
185