sccs2rcs.in revision 102843
1#! @CSH@ -f 2# 3# Sccs2rcs is a script to convert an existing SCCS 4# history into an RCS history without losing any of 5# the information contained therein. 6# It has been tested under the following OS's: 7# SunOS 3.5, 4.0.3, 4.1 8# Ultrix-32 2.0, 3.1 9# 10# Things to note: 11# + It will NOT delete or alter your ./SCCS history under any circumstances. 12# 13# + Run in a directory where ./SCCS exists and where you can 14# create ./RCS 15# 16# + /usr/local/bin is put in front of the default path. 17# (SCCS under Ultrix is set-uid sccs, bad bad bad, so 18# /usr/local/bin/sccs here fixes that) 19# 20# + Date, time, author, comments, branches, are all preserved. 21# 22# + If a command fails somewhere in the middle, it bombs with 23# a message -- remove what it's done so far and try again. 24# "rm -rf RCS; sccs unedit `sccs tell`; sccs clean" 25# There is no recovery and exit is far from graceful. 26# If a particular module is hanging you up, consider 27# doing it separately; move it from the current area so that 28# the next run will have a better chance or working. 29# Also (for the brave only) you might consider hacking 30# the s-file for simpler problems: I've successfully changed 31# the date of a delta to be in sync, then run "sccs admin -z" 32# on the thing. 33# 34# + After everything finishes, ./SCCS will be moved to ./old-SCCS. 35# 36# This file may be copied, processed, hacked, mutilated, and 37# even destroyed as long as you don't tell anyone you wrote it. 38# 39# Ken Cox 40# Viewlogic Systems, Inc. 41# kenstir@viewlogic.com 42# ...!harvard!cg-atla!viewlog!kenstir 43# 44# Various hacks made by Brian Berliner before inclusion in CVS contrib area. 45# $FreeBSD: head/contrib/cvs/contrib/sccs2rcs.in 102843 2002-09-02 05:57:14Z peter $ 46 47 48#we'll assume the user set up the path correctly 49# for the Pmax, /usr/ucb/sccs is suid sccs, what a pain 50# /usr/local/bin/sccs should override /usr/ucb/sccs there 51set path = (/usr/local/bin $path) 52 53 54############################################################ 55# Error checking 56# 57if (! -w .) then 58 echo "Error: ./ not writeable by you." 59 exit 1 60endif 61if (! -d SCCS) then 62 echo "Error: ./SCCS directory not found." 63 exit 1 64endif 65set edits = (`sccs tell`) 66if ($#edits) then 67 echo "Error: $#edits file(s) out for edit...clean up before converting." 68 exit 1 69endif 70if (-d RCS) then 71 echo "Warning: RCS directory exists" 72 if (`ls -a RCS | wc -l` > 2) then 73 echo "Error: RCS directory not empty" 74 exit 1 75 endif 76else 77 mkdir RCS 78endif 79 80sccs clean 81 82set logfile = /tmp/sccs2rcs_$$_log 83rm -f $logfile 84set tmpfile = /tmp/sccs2rcs_$$_tmp 85rm -f $tmpfile 86set emptyfile = /tmp/sccs2rcs_$$_empty 87echo -n "" > $emptyfile 88set initialfile = /tmp/sccs2rcs_$$_init 89echo "Initial revision" > $initialfile 90set sedfile = /tmp/sccs2rcs_$$_sed 91rm -f $sedfile 92set revfile = /tmp/sccs2rcs_$$_rev 93rm -f $revfile 94 95# the quotes surround the dollar signs to fool RCS when I check in this script 96set sccs_keywords = (\ 97 '%W%[ ]*%G%'\ 98 '%W%[ ]*%E%'\ 99 '%W%'\ 100 '%Z%%M%[ ]*%I%[ ]*%G%'\ 101 '%Z%%M%[ ]*%I%[ ]*%E%'\ 102 '%M%[ ]*%I%[ ]*%G%'\ 103 '%M%[ ]*%I%[ ]*%E%'\ 104 '%M%'\ 105 '%I%'\ 106 '%G%'\ 107 '%E%'\ 108 '%U%') 109set rcs_keywords = (\ 110 '$'Id'$'\ 111 '$'Id'$'\ 112 '$'Id'$'\ 113 '$'SunId'$'\ 114 '$'SunId'$'\ 115 '$'Id'$'\ 116 '$'Id'$'\ 117 '$'RCSfile'$'\ 118 '$'Revision'$'\ 119 '$'Date'$'\ 120 '$'Date'$'\ 121 '') 122 123 124############################################################ 125# Get some answers from user 126# 127echo "" 128echo "Do you want to be prompted for a description of each" 129echo "file as it is checked in to RCS initially?" 130echo -n "(y=prompt for description, n=null description) [y] ?" 131set ans = $< 132if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then 133 set nodesc = 0 134else 135 set nodesc = 1 136endif 137echo "" 138echo "The default keyword substitutions are as follows and are" 139echo "applied in the order specified:" 140set i = 1 141while ($i <= $#sccs_keywords) 142# echo ' '\"$sccs_keywords[$i]\"' ==> '\"$rcs_keywords[$i]\" 143 echo " $sccs_keywords[$i] ==> $rcs_keywords[$i]" 144 @ i = $i + 1 145end 146echo "" 147echo -n "Do you want to change them [n] ?" 148set ans = $< 149if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then 150 echo "You can't always get what you want." 151 echo "Edit this script file and change the variables:" 152 echo ' $sccs_keywords' 153 echo ' $rcs_keywords' 154else 155 echo "good idea." 156endif 157 158# create the sed script 159set i = 1 160while ($i <= $#sccs_keywords) 161 echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile 162 @ i = $i + 1 163end 164 165onintr ERROR 166 167############################################################ 168# Loop over every s-file in SCCS dir 169# 170foreach sfile (SCCS/s.*) 171 # get rid of the "s." at the beginning of the name 172 set file = `echo $sfile:t | sed -e "s/^..//"` 173 174 # work on each rev of that file in ascending order 175 set firsttime = 1 176 sccs prs $file | grep "^D " | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile 177 foreach rev (`cat $revfile`) 178 if ($status != 0) goto ERROR 179 180 # get file into current dir and get stats 181 182 # Is the substr stuff and the +0 in the following awk script really 183 # necessary? It seems to me that if we didn't find the date format 184 # we expected in the output we have other problems. 185 set date = `sccs prs -r$rev $file | awk '/^D / {print (substr($3,0,2)+0<70?20:19) $3, $4; exit}'` 186 set author = `sccs prs -r$rev $file | awk '/^D / {print $5; exit}'` 187 echo "" 188 echo "==> file $file, rev=$rev, date=$date, author=$author" 189 sccs edit -r$rev $file >>& $logfile 190 if ($status != 0) goto ERROR 191 echo checked out of SCCS 192 193 # add RCS keywords in place of SCCS keywords 194 sed -f $sedfile $file > $tmpfile 195 if ($status != 0) goto ERROR 196 echo performed keyword substitutions 197 cp $tmpfile $file 198 199 # check file into RCS 200 if ($firsttime) then 201 set firsttime = 0 202 if ($nodesc) then 203 echo about to do ci 204 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 205 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile 206 if ($status != 0) goto ERROR 207 echo initial rev checked into RCS without description 208 else 209 echo "" 210 echo Enter a brief description of the file $file \(end w/ Ctrl-D\): 211 cat > $tmpfile 212 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile 213 if ($status != 0) goto ERROR 214 echo initial rev checked into RCS 215 endif 216 else 217 # get RCS lock 218 set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'` 219 if ("$lckrev" =~ [0-9]*.*) then 220 # need to lock the brach -- it is OK if the lock fails 221 rcs -l$lckrev $file >>& $logfile 222 else 223 # need to lock the trunk -- must succeed 224 rcs -l $file >>& $logfile 225 if ($status != 0) goto ERROR 226 endif 227 echo got lock 228 sccs prs -r$rev $file | grep "." > $tmpfile 229 # it's OK if grep fails here and gives status == 1 230 # put the delta message in $tmpfile 231 ed $tmpfile >>& $logfile <<EOF 232/COMMENTS 2331,.d 234w 235q 236EOF 237 ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile 238 if ($status != 0) goto ERROR 239 echo checked into RCS 240 endif 241 sccs unedit $file >>& $logfile 242 if ($status != 0) goto ERROR 243 end 244 rm -f $file 245end 246 247 248############################################################ 249# Clean up 250# 251echo cleaning up... 252mv SCCS old-SCCS 253rm -f $tmpfile $emptyfile $initialfile $sedfile 254echo =================================================== 255echo " Conversion Completed Successfully" 256echo "" 257echo " SCCS history now in old-SCCS/" 258echo =================================================== 259set exitval = 0 260goto cleanup 261 262ERROR: 263foreach f (`sccs tell`) 264 sccs unedit $f 265end 266echo "" 267echo "" 268echo Danger\! Danger\! 269echo Some command exited with a non-zero exit status. 270echo Log file exists in $logfile. 271echo "" 272echo Incomplete history in ./RCS -- remove it 273echo Original unchanged history in ./SCCS 274set exitval = 1 275 276cleanup: 277# leave log file 278rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile 279 280exit $exitval 281