/contrib/cvs/contrib/rcs-to-cvs.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 193 lines · 139 code · 14 blank · 40 comment · 29 complexity · 345d3a1bbb152dbd31067e9cdd342b04 MD5 · raw file

  1. #! /bin/sh
  2. #
  3. # Copyright (c) 1989-2005 The Free Software Foundation, Inc.
  4. # Portions Copyright (c) 1989, Brian Berliner
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # Based on the CVS 1.0 checkin csh script.
  17. # Contributed by Per Cederqvist <ceder@signum.se>.
  18. # Rewritten in sh by David MacKenzie <djm@cygnus.com>.
  19. #
  20. #############################################################################
  21. #
  22. # Check in sources that previously were under RCS or no source control system.
  23. #
  24. # The repository is the directory where the sources should be deposited.
  25. #
  26. # Traverses the current directory, ensuring that an
  27. # identical directory structure exists in the repository directory. It
  28. # then checks the files in in the following manner:
  29. #
  30. # 1) If the file doesn't yet exist, check it in as revision 1.1
  31. #
  32. # The script also is somewhat verbose in letting the user know what is
  33. # going on. It prints a diagnostic when it creates a new file, or updates
  34. # a file that has been modified on the trunk.
  35. #
  36. # Bugs: doesn't put the files in branch 1.1.1
  37. # doesn't put in release and vendor tags
  38. #
  39. #############################################################################
  40. usage="Usage: rcs-to-cvs [-v] [-m message] [-f message_file] repository"
  41. vbose=0
  42. message=""
  43. if [ -d /var/tmp ]; then message_file=/var/tmp/checkin.$$; else message_file=/usr/tmp/checkin.$$; fi
  44. got_one=0
  45. if [ $# -lt 1 ]; then
  46. echo "$usage" >&2
  47. exit 1
  48. fi
  49. while [ $# -ne 0 ]; do
  50. case "$1" in
  51. -v)
  52. vbose=1
  53. ;;
  54. -m)
  55. shift
  56. echo $1 > $message_file
  57. got_one=1
  58. ;;
  59. -f)
  60. shift
  61. message_file=$1
  62. got_one=2
  63. ;;
  64. *)
  65. break
  66. esac
  67. shift
  68. done
  69. if [ $# -lt 1 ]; then
  70. echo "$usage" >&2
  71. exit 1
  72. fi
  73. repository=$1
  74. shift
  75. if [ -z "$CVSROOT" ]; then
  76. echo "Please the environmental variable CVSROOT to the root" >&2
  77. echo " of the tree you wish to update" >&2
  78. exit 1
  79. fi
  80. if [ $got_one -eq 0 ]; then
  81. echo "Please Edit this file to contain the RCS log information" >$message_file
  82. echo "to be associated with this directory (please remove these lines)">>$message_file
  83. ${EDITOR-vi} $message_file
  84. got_one=1
  85. fi
  86. # Ya gotta share.
  87. umask 0
  88. update_dir=${CVSROOT}/${repository}
  89. [ ! -d ${update_dir} ] && mkdir $update_dir
  90. if [ -d SCCS ]; then
  91. echo SCCS files detected! >&2
  92. exit 1
  93. fi
  94. if [ -d RCS ]; then
  95. co RCS/*
  96. fi
  97. for name in * .[a-zA-Z0-9]*
  98. do
  99. case "$name" in
  100. RCS | *~ | \* | .\[a-zA-Z0-9\]\* ) continue ;;
  101. esac
  102. echo $name
  103. if [ $vbose -ne 0 ]; then
  104. echo "Updating ${repository}/${name}"
  105. fi
  106. if [ -d "$name" ]; then
  107. if [ ! -d "${update_dir}/${name}" ]; then
  108. echo "WARNING: Creating new directory ${repository}/${name}"
  109. mkdir "${update_dir}/${name}"
  110. if [ $? -ne 0 ]; then
  111. echo "ERROR: mkdir failed - aborting" >&2
  112. exit 1
  113. fi
  114. fi
  115. cd "$name"
  116. if [ $? -ne 0 ]; then
  117. echo "ERROR: Couldn\'t cd to $name - aborting" >&2
  118. exit 1
  119. fi
  120. if [ $vbose -ne 0 ]; then
  121. $0 -v -f $message_file "${repository}/${name}"
  122. else
  123. $0 -f $message_file "${repository}/${name}"
  124. fi
  125. if [ $? -ne 0 ]; then
  126. exit 1
  127. fi
  128. cd ..
  129. else # if not directory
  130. if [ ! -f "$name" ]; then
  131. echo "WARNING: $name is neither a regular file"
  132. echo " nor a directory - ignored"
  133. continue
  134. fi
  135. file="${update_dir}/${name},v"
  136. comment=""
  137. if grep -s '\$Log.*\$' "${name}"; then # If $Log keyword
  138. myext=`echo $name | sed 's,.*\.,,'`
  139. [ "$myext" = "$name" ] && myext=
  140. case "$myext" in
  141. c | csh | e | f | h | l | mac | me | mm | ms | p | r | red | s | sh | sl | cl | ml | el | tex | y | ye | yr | "" )
  142. ;;
  143. * )
  144. echo "For file ${file}:"
  145. grep '\$Log.*\$' "${name}"
  146. echo -n "Please insert a comment leader for file ${name} > "
  147. read comment
  148. ;;
  149. esac
  150. fi
  151. if [ ! -f "$file" ]; then # If not exists in repository
  152. if [ ! -f "${update_dir}/Attic/${name},v" ]; then
  153. echo "WARNING: Creating new file ${repository}/${name}"
  154. if [ -f RCS/"${name}",v ]; then
  155. echo "MSG: Copying old rcs file."
  156. cp RCS/"${name}",v "$file"
  157. else
  158. if [ -n "${comment}" ]; then
  159. rcs -q -i -c"${comment}" -t${message_file} -m'.' "$file"
  160. fi
  161. ci -q -u1.1 -t${message_file} -m'.' "$file"
  162. if [ $? -ne 0 ]; then
  163. echo "ERROR: Initial check-in of $file failed - aborting" >&2
  164. exit 1
  165. fi
  166. fi
  167. else
  168. file="${update_dir}/Attic/${name},v"
  169. echo "WARNING: IGNORED: ${repository}/Attic/${name}"
  170. continue
  171. fi
  172. else # File existed
  173. echo "ERROR: File exists in repository: Ignored: $file"
  174. continue
  175. fi
  176. fi
  177. done
  178. [ $got_one -eq 1 ] && rm -f $message_file
  179. exit 0