summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/cvs/contrib/rcs-to-cvs
blob: 5863ed87414c3de6a9a395277231ff522a49818d (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
#
# $Id: rcs-to-cvs,v 1.4 1994/09/21 07:23:16 berliner Exp $
# Based on the CVS 1.0 checkin csh script.
# Contributed by Per Cederqvist <ceder@signum.se>.
# Rewritten in sh by David MacKenzie <djm@cygnus.com>.
#
#   Copyright (c) 1989, Brian Berliner
#
#   You may distribute under the terms of the GNU General Public License.
#
#############################################################################
#
# Check in sources that previously were under RCS or no source control system.
#
# The repository is the directory where the sources should be deposited.
#
# Traverses the current directory, ensuring that an
# identical directory structure exists in the repository directory.  It
# then checks the files in in the following manner:
#
#		1) If the file doesn't yet exist, check it in as revision 1.1
#
# The script also is somewhat verbose in letting the user know what is
# going on.  It prints a diagnostic when it creates a new file, or updates
# a file that has been modified on the trunk.
#
# Bugs: doesn't put the files in branch 1.1.1
#       doesn't put in release and vendor tags
#
#############################################################################

usage="Usage: rcs-to-cvs [-v] [-m message] [-f message_file] repository"
vbose=0
message=""
message_file=/usr/tmp/checkin.$$
got_one=0

if [ $# -lt 1 ]; then
    echo "$usage" >&2
    exit 1
fi

while [ $# -ne 0 ]; do
    case "$1" in
        -v)
            vbose=1
	    ;;
	-m)
	    shift
	    echo $1 > $message_file
	    got_one=1
	    ;;
	-f)
	    shift
	    message_file=$1
	    got_one=2
	    ;;
	*)
	    break
    esac
    shift
done

if [ $# -lt 1 ]; then
    echo "$usage" >&2
    exit 1
fi

repository=$1
shift

if [ -z "$CVSROOT" ]; then
    echo "Please the environmental variable CVSROOT to the root" >&2
    echo "	of the tree you wish to update" >&2
    exit 1
fi

if [ $got_one -eq 0 ]; then
    echo "Please Edit this file to contain the RCS log information" >$message_file
    echo "to be associated with this directory (please remove these lines)">>$message_file
    ${EDITOR-/usr/ucb/vi} $message_file
    got_one=1
fi

umask 22

update_dir=${CVSROOT}/${repository}
[ ! -d ${update_dir} ] && mkdir $update_dir

if [ -d SCCS ]; then
    echo SCCS files detected! >&2
    exit 1
fi
if [ -d RCS ]; then
    co RCS/*
fi

for name in * .[a-zA-Z0-9]*
do
    case "$name" in
    RCS | \* | .\[a-zA-Z0-9\]\* ) continue ;;
    esac
    echo $name
    if [ $vbose -ne 0 ]; then 
	echo "Updating ${repository}/${name}"
    fi
    if [ -d "$name" ]; then
	if [ ! -d "${update_dir}/${name}" ]; then
	    echo "WARNING: Creating new directory ${repository}/${name}"
	    mkdir "${update_dir}/${name}"
	    if [ $? -ne 0 ]; then
		echo "ERROR: mkdir failed - aborting" >&2
		exit 1
	    fi
	fi
	cd "$name"
	if [ $? -ne 0 ]; then
	    echo "ERROR: Couldn\'t cd to $name - aborting" >&2
	    exit 1
	fi
	if [ $vbose -ne 0 ]; then
	    $0 -v -f $message_file "${repository}/${name}"
	else
	    $0 -f $message_file "${repository}/${name}"
	fi
	if [ $? -ne 0 ]; then 
	    exit 1
	fi
	cd ..
    else	# if not directory 
	if [ ! -f "$name" ]; then
	    echo "WARNING: $name is neither a regular file"
	    echo "	   nor a directory - ignored"
	    continue
	fi
	file="${update_dir}/${name},v"
	comment=""
	if grep -s '\$Log.*\$' "${name}"; then # If $Log keyword
	    myext=`echo $name | sed 's,.*\.,,'`
	    [ "$myext" = "$name" ] && myext=
	    case "$myext" in
		c | csh | e | f | h | l | mac | me | mm | ms | p | r | red | s | sh | sl | cl | ml | el | tex | y | ye | yr | "" )
		;;

		* )
		echo "For file ${file}:"
		grep '\$Log.*\$' "${name}"
		echo -n "Please insert a comment leader for file ${name} > "
		read comment
		;;
	    esac
	fi
	if [ ! -f "$file" ]; then	# If not exists in repository
	    if [ ! -f "${update_dir}/Attic/${name},v" ]; then
	        echo "WARNING: Creating new file ${repository}/${name}"
		if [ -f RCS/"${name}",v ]; then
			echo "MSG: Copying old rcs file."
			cp RCS/"${name}",v "$file"
		else
   		    if [ -n "${comment}" ]; then
		        rcs -q -i -c"${comment}" -t${message_file} -m'.' "$file"
		    fi
	            ci -q -u1.1 -t${message_file} -m'.' "$file" 
	            if [ $? -ne 0 ]; then
		        echo "ERROR: Initial check-in of $file failed - aborting" >&2
		        exit 1
	            fi
		fi
	    else 
		file="${update_dir}/Attic/${name},v"
		echo "WARNING: IGNORED: ${repository}/Attic/${name}"
		continue
	    fi
	else	# File existed 
	    echo "ERROR: File exists in repository: Ignored: $file"
	    continue
	fi
    fi
done

[ $got_one -eq 1 ] && rm -f $message_file

exit 0
OpenPOWER on IntegriCloud