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 46 47#we'll assume the user set up the path correctly 48# for the Pmax, /usr/ucb/sccs is suid sccs, what a pain 49# /usr/local/bin/sccs should override /usr/ucb/sccs there 50set path = (/usr/local/bin $path) 51 52 53############################################################ 54# Error checking 55# 56if (! -w .) then 57 echo "Error: ./ not writeable by you." 58 exit 1 59endif 60if (! -d SCCS) then 61 echo "Error: ./SCCS directory not found." 62 exit 1 63endif 64set edits = (`sccs tell`) 65if ($#edits) then 66 echo "Error: $#edits file(s) out for edit...clean up before converting." 67 exit 1 68endif 69if (-d RCS) then 70 echo "Warning: RCS directory exists" 71 if (`ls -a RCS | wc -l` > 2) then 72 echo "Error: RCS directory not empty 73 exit 1 74 endif 75else 76 mkdir RCS 77endif 78 79sccs clean 80 81set logfile = /tmp/sccs2rcs_$$_log 82rm -f $logfile 83set tmpfile = /tmp/sccs2rcs_$$_tmp 84rm -f $tmpfile 85set emptyfile = /tmp/sccs2rcs_$$_empty 86echo -n "" > $emptyfile 87set initialfile = /tmp/sccs2rcs_$$_init 88echo "Initial revision" > $initialfile 89set sedfile = /tmp/sccs2rcs_$$_sed 90rm -f $sedfile 91set revfile = /tmp/sccs2rcs_$$_rev 92rm -f $revfile 93 94# the quotes surround the dollar signs to fool RCS when I check in this script 95set sccs_keywords = (\ 96 '%W%[ ]*%G%'\ 97 '%W%[ ]*%E%'\ 98 '%W%'\ 99 '%Z%%M%[ ]*%I%[ ]*%G%'\ 100 '%Z%%M%[ ]*%I%[ ]*%E%'\ 101 '%M%[ ]*%I%[ ]*%G%'\ 102 '%M%[ ]*%I%[ ]*%E%'\ 103 '%M%'\ 104 '%I%'\ 105 '%G%'\ 106 '%E%'\ 107 '%U%') 108set rcs_keywords = (\ 109 '$'Id'$'\ 110 '$'Id'$'\ 111 '$'Id'$'\ 112 '$'SunId'$'\ 113 '$'SunId'$'\ 114 '$'Id'$'\ 115 '$'Id'$'\ 116 '$'RCSfile'$'\ 117 '$'Revision'$'\ 118 '$'Date'$'\ 119 '$'Date'$'\ 120 '') 121 122 123############################################################ 124# Get some answers from user 125# 126echo "" 127echo "Do you want to be prompted for a description of each" 128echo "file as it is checked in to RCS initially?" 129echo -n "(y=prompt for description, n=null description) [y] ?" 130set ans = $< 131if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then 132 set nodesc = 0 133else 134 set nodesc = 1 135endif 136echo "" 137echo "The default keyword substitutions are as follows and are" 138echo "applied in the order specified:" 139set i = 1 140while ($i <= $#sccs_keywords) 141# echo ' '\"$sccs_keywords[$i]\"' ==> '\"$rcs_keywords[$i]\" 142 echo " $sccs_keywords[$i] ==> $rcs_keywords[$i]" 143 @ i = $i + 1 144end 145echo "" 146echo -n "Do you want to change them [n] ?" 147set ans = $< 148if ((_$ans != _) && (_$ans != _n) && (_$ans != _N)) then 149 echo "You can't always get what you want." 150 echo "Edit this script file and change the variables:" 151 echo ' $sccs_keywords' 152 echo ' $rcs_keywords' 153else 154 echo "good idea." 155endif 156 157# create the sed script 158set i = 1 159while ($i <= $#sccs_keywords) 160 echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile 161 @ i = $i + 1 162end 163 164onintr ERROR 165 166############################################################ 167# Loop over every s-file in SCCS dir 168# 169foreach sfile (SCCS/s.*) 170 # get rid of the "s." at the beginning of the name 171 set file = `echo $sfile:t | sed -e "s/^..//"` 172 173 # work on each rev of that file in ascending order 174 set firsttime = 1 175 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 176 foreach rev (`cat $revfile`) 177 if ($status != 0) goto ERROR 178 179 # get file into current dir and get stats 180 set year = `echo $date | cut -c3-4` 181 if ($year < 70) then 182 # Y2K Bug, change century to 20 183 set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("20%s %s", $3, $4); exit}'` 184 else 185 set date = `sccs prs -r$rev $file | grep "^D " | awk '{printf("19%s %s", $3, $4); exit}'` 186 endif 187 set author = `sccs prs -r$rev $file | grep "^D " | awk '{print $5; exit}'` 188 echo "" 189 echo "==> file $file, rev=$rev, date=$date, author=$author" 190 sccs edit -r$rev $file >>& $logfile 191 if ($status != 0) goto ERROR 192 echo checked out of SCCS 193 194 # add RCS keywords in place of SCCS keywords 195 sed -f $sedfile $file > $tmpfile 196 if ($status != 0) goto ERROR 197 echo performed keyword substitutions 198 cp $tmpfile $file 199 200 # check file into RCS 201 if ($firsttime) then 202 set firsttime = 0 203 if ($nodesc) then 204 echo about to do ci 205 echo ci -f -r$rev -d"$date" -w$author -t$emptyfile $file 206 ci -f -r$rev -d"$date" -w$author -t$emptyfile $file < $initialfile >>& $logfile 207 if ($status != 0) goto ERROR 208 echo initial rev checked into RCS without description 209 else 210 echo "" 211 echo Enter a brief description of the file $file \(end w/ Ctrl-D\): 212 cat > $tmpfile 213 ci -f -r$rev -d"$date" -w$author -t$tmpfile $file < $initialfile >>& $logfile 214 if ($status != 0) goto ERROR 215 echo initial rev checked into RCS 216 endif 217 else 218 # get RCS lock 219 set lckrev = `echo $rev | sed -e 's/\.[0-9]*$//'` 220 if ("$lckrev" =~ [0-9]*.*) then 221 # need to lock the brach -- it is OK if the lock fails 222 rcs -l$lckrev $file >>& $logfile 223 else 224 # need to lock the trunk -- must succeed 225 rcs -l $file >>& $logfile 226 if ($status != 0) goto ERROR 227 endif 228 echo got lock 229 sccs prs -r$rev $file | grep "." > $tmpfile 230 # it's OK if grep fails here and gives status == 1 231 # put the delta message in $tmpfile 232 ed $tmpfile >>& $logfile <<EOF 233/COMMENTS 2341,.d 235w 236q 237EOF 238 ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile 239 if ($status != 0) goto ERROR 240 echo checked into RCS 241 endif 242 sccs unedit $file >>& $logfile 243 if ($status != 0) goto ERROR 244 end 245 rm -f $file 246end 247 248 249############################################################ 250# Clean up 251# 252echo cleaning up... 253mv SCCS old-SCCS 254rm -f $tmpfile $emptyfile $initialfile $sedfile 255echo =================================================== 256echo " Conversion Completed Successfully" 257echo "" 258echo " SCCS history now in old-SCCS/" 259echo =================================================== 260set exitval = 0 261goto cleanup 262 263ERROR: 264foreach f (`sccs tell`) 265 sccs unedit $f 266end 267echo "" 268echo "" 269echo Danger\! Danger\! 270echo Some command exited with a non-zero exit status. 271echo Log file exists in $logfile. 272echo "" 273echo Incomplete history in ./RCS -- remove it 274echo Original unchanged history in ./SCCS 275set exitval = 1 276 277cleanup: 278# leave log file 279rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile 280 281exit $exitval 282