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