/contrib/cvs/contrib/sccs2rcs.in

https://bitbucket.org/freebsd/freebsd-head/ · Autoconf · 327 lines · 194 code · 29 blank · 104 comment · 44 complexity · 3707de5898f534832c9eecf9dc802548 MD5 · raw file

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