/contrib/cvs/contrib/rcs2sccs.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 156 lines · 118 code · 9 blank · 29 comment · 20 complexity · 1b7c467229cccb4a31b090a5263966df MD5 · raw file

  1. #! /bin/sh
  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. ############################################################
  16. # Error checking
  17. #
  18. if [ ! -d SCCS ] ; then
  19. mkdir SCCS
  20. fi
  21. logfile=/tmp/rcs2sccs_$$_log
  22. rm -f $logfile
  23. tmpfile=/tmp/rcs2sccs_$$_tmp
  24. rm -f $tmpfile
  25. emptyfile=/tmp/rcs2sccs_$$_empty
  26. echo -n "" > $emptyfile
  27. initialfile=/tmp/rcs2sccs_$$_init
  28. echo "Initial revision" > $initialfile
  29. sedfile=/tmp/rcs2sccs_$$_sed
  30. rm -f $sedfile
  31. revfile=/tmp/rcs2sccs_$$_rev
  32. rm -f $revfile
  33. commentfile=/tmp/rcs2sccs_$$_comment
  34. rm -f $commentfile
  35. # create the sed script
  36. cat > $sedfile << EOF
  37. s,;Id;,%Z%%M% %I% %E%,g
  38. s,;SunId;,%Z%%M% %I% %E%,g
  39. s,;RCSfile;,%M%,g
  40. s,;Revision;,%I%,g
  41. s,;Date;,%E%,g
  42. s,;Id:.*;,%Z%%M% %I% %E%,g
  43. s,;SunId:.*;,%Z%%M% %I% %E%,g
  44. s,;RCSfile:.*;,%M%,g
  45. s,;Revision:.*;,%I%,g
  46. s,;Date:.*;,%E%,g
  47. EOF
  48. sed -e 's/;/\\$/g' $sedfile > $tmpfile
  49. cp $tmpfile $sedfile
  50. ############################################################
  51. # Loop over every RCS file in RCS dir
  52. #
  53. if sort -k 1,1 /dev/null 2>/dev/null
  54. then sort_each_field='-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9'
  55. else sort_each_field='+0 +1 +2 +3 +4 +5 +6 +7 +8'
  56. fi
  57. for vfile in *,v; do
  58. # get rid of the ",v" at the end of the name
  59. file=`echo $vfile | sed -e 's/,v$//'`
  60. # work on each rev of that file in ascending order
  61. firsttime=1
  62. rlog $file | grep "^revision [0-9][0-9]*\." | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u $sort_each_field | sed -e 's/ /./g' > $revfile
  63. for rev in `cat $revfile`; do
  64. if [ $? != 0 ]; then
  65. echo ERROR - revision
  66. exit
  67. fi
  68. # get file into current dir and get stats
  69. date=`rlog -r$rev $file | grep "^date: " | awk '{print $2; exit}' | sed -e 's/^19\|^20//'`
  70. time=`rlog -r$rev $file | grep "^date: " | awk '{print $3; exit}' | sed -e 's/;//'`
  71. author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
  72. date="$date $time"
  73. echo ""
  74. rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' -e 's/$/\\/' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
  75. echo "==> file $file, rev=$rev, date=$date, author=$author"
  76. rm -f $file
  77. co -r$rev $file >> $logfile 2>&1
  78. if [ $? != 0 ]; then
  79. echo ERROR - co
  80. exit
  81. fi
  82. echo checked out of RCS
  83. # add SCCS keywords in place of RCS keywords
  84. sed -f $sedfile $file > $tmpfile
  85. if [ $? != 0 ]; then
  86. echo ERROR - sed
  87. exit
  88. fi
  89. echo performed keyword substitutions
  90. rm -f $file
  91. cp $tmpfile $file
  92. # check file into SCCS
  93. if [ "$firsttime" = "1" ]; then
  94. firsttime=0
  95. echo about to do sccs admin
  96. echo sccs admin -n -i$file $file < $commentfile
  97. sccs admin -n -i$file $file < $commentfile >> $logfile 2>&1
  98. if [ $? != 0 ]; then
  99. echo ERROR - sccs admin
  100. exit
  101. fi
  102. echo initial rev checked into SCCS
  103. else
  104. case $rev in
  105. *.*.*.*)
  106. brev=`echo $rev | sed -e 's/\.[0-9]*$//'`
  107. sccs admin -fb $file 2>>$logfile
  108. echo sccs get -e -p -r$brev $file
  109. sccs get -e -p -r$brev $file >/dev/null 2>>$logfile
  110. ;;
  111. *)
  112. echo sccs get -e -p $file
  113. sccs get -e -p $file >/dev/null 2>> $logfile
  114. ;;
  115. esac
  116. if [ $? != 0 ]; then
  117. echo ERROR - sccs get
  118. exit
  119. fi
  120. sccs delta $file < $commentfile >> $logfile 2>&1
  121. if [ $? != 0 ]; then
  122. echo ERROR - sccs delta -r$rev $file
  123. exit
  124. fi
  125. echo checked into SCCS
  126. fi
  127. sed -e "s;^d D $rev ../../.. ..:..:.. [^ ][^ ]*;d D $rev $date $author;" SCCS/s.$file > $tmpfile
  128. rm -f SCCS/s.$file
  129. cp $tmpfile SCCS/s.$file
  130. chmod 444 SCCS/s.$file
  131. sccs admin -z $file
  132. if [ $? != 0 ]; then
  133. echo ERROR - sccs admin -z
  134. exit
  135. fi
  136. done
  137. rm -f $file
  138. done
  139. ############################################################
  140. # Clean up
  141. #
  142. echo cleaning up...
  143. rm -f $tmpfile $emptyfile $initialfile $sedfile $commentfile
  144. echo ===================================================
  145. echo " Conversion Completed Successfully"
  146. echo ===================================================
  147. rm -f *,v