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