3 # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
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)
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.
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
23 # + It will NOT delete or alter your ./SCCS history under any circumstances.
25 # + Run in a directory where ./SCCS exists and where you can
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)
32 # + Date, time, author, comments, branches, are all preserved.
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"
46 # + After everything finishes, ./SCCS will be moved to ./old-SCCS.
48 # This file may be copied, processed, hacked, mutilated, and
49 # even destroyed as long as you don't tell anyone you wrote it.
52 # Viewlogic Systems, Inc.
53 # kenstir@viewlogic.com
54 # ...!harvard!cg-atla!viewlog!kenstir
56 # Various hacks made by Brian Berliner before inclusion in CVS contrib area.
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
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
69 set path = (/usr/local/bin $path)
72 ############################################################
76 echo "Error: ./ not writeable by you."
80 echo "Error: ./SCCS directory not found."
83 set edits = (`sccs tell`)
85 echo "Error: $#edits file(s) out for edit...clean up before converting."
89 echo "Warning: RCS directory exists"
90 if (`ls -a RCS | wc -l` > 2) then
91 echo "Error: RCS directory not empty"
100 set logfile = /tmp/sccs2rcs_$$_log
102 set tmpfile = /tmp/sccs2rcs_$$_tmp
104 set emptyfile = /tmp/sccs2rcs_$$_empty
105 echo -n "" > $emptyfile
106 set initialfile = /tmp/sccs2rcs_$$_init
107 echo "Initial revision" > $initialfile
108 set sedfile = /tmp/sccs2rcs_$$_sed
110 set revfile = /tmp/sccs2rcs_$$_rev
113 # the quotes surround the dollar signs to fool RCS when I check in this script
114 set sccs_keywords = (\
118 '%Z%%M%[ ]*%I%[ ]*%G%'\
119 '%Z%%M%[ ]*%I%[ ]*%E%'\
127 set rcs_keywords = (\
142 ############################################################
143 # Get some answers from user
146 echo "Do you want to be prompted for a description of each"
147 echo "file as it is checked in to RCS initially?"
148 echo -n "(y=prompt for description, n=null description) [y] ?"
150 if ((_$ans == _) || (_$ans == _y) || (_$ans == _Y)) then
156 echo "The default keyword substitutions are as follows and are"
157 echo "applied in the order specified:"
159 while ($i <= $#sccs_keywords)
160 # echo ' '\"$sccs_keywords[$i]\"' ==> '\"$rcs_keywords[$i]\"
161 echo " $sccs_keywords[$i] ==> $rcs_keywords[$i]"
165 echo -n "Do you want to change them [n] ?"
167 if ((_$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'
176 # create the sed script
178 while ($i <= $#sccs_keywords)
179 echo "s,$sccs_keywords[$i],$rcs_keywords[$i],g" >> $sedfile
185 sort -k 1,1 /dev/null >& /dev/null
186 if ($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'
189 set sort_each_field = '+0 +1 +2 +3 +4 +5 +6 +7 +8'
192 ############################################################
193 # Loop over every s-file in SCCS dir
195 foreach sfile (SCCS/s.*)
196 # get rid of the "s." at the beginning of the name
197 set file = `echo $sfile:t | sed -e "s/^..//"`
199 # work on each rev of that file in ascending order
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$'`)
207 # echo This is a binary file
209 # echo This is not a binary file
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
216 # get file into current dir and get stats
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}'`
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
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
239 # check file into RCS
244 echo this is a binary file
245 # Mark initial, empty file as binary
246 rcs -i -kb -t$emptyfile $file
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
257 echo Enter a brief description of the file $file \(end w/ Ctrl-D\):
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
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
270 # need to lock the trunk -- must succeed
271 rcs -l $file >>& $logfile
272 if ($status != 0) goto ERROR
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
284 ci -f -r$rev -d"$date" -w$author $file < $tmpfile >>& $logfile
285 if ($status != 0) goto ERROR
286 echo checked into RCS
288 sccs unedit $file >>& $logfile
289 if ($status != 0) goto ERROR
295 ############################################################
300 rm -f $tmpfile $emptyfile $initialfile $sedfile
301 echo ===================================================
302 echo " Conversion Completed Successfully"
304 echo " SCCS history now in old-SCCS/"
305 echo ===================================================
310 foreach f (`sccs tell`)
315 echo Danger\! Danger\!
316 echo Some command exited with a non-zero exit status.
317 echo Log file exists in $logfile.
319 echo Incomplete history in ./RCS -- remove it
320 echo Original unchanged history in ./SCCS
325 rm -f $tmpfile $emptyfile $initialfile $sedfile $revfile