PageRenderTime 44ms CodeModel.GetById 22ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 1ms

/contrib/cvs/contrib/rcs-to-cvs.sh

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