home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / checkin.csh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1991-02-06  |  8KB  |  266 lines

  1. #!/bin/csh
  2. #
  3. # $Id: checkin.csh,v 1.8.1.1 91/01/18 12:06:34 berliner Exp $
  4. #
  5. #   Copyright (c) 1989, Brian Berliner
  6. #
  7. #   You may distribute under the terms of the GNU General Public License
  8. #   as specified in the README file that comes with the CVS 1.0 kit.
  9. #
  10. #############################################################################
  11. #                                        #
  12. # This script is used to check in sources from vendors.              #
  13. #                                        #
  14. #    Usage: checkin repository Vendor_Tag Vendor_Release_Tag            #
  15. #                                        #
  16. # The repository is the directory where the sources should            #
  17. # be deposited, the Vendor_Tag is the symbolic tag for the             #
  18. # vendor branch of the RCS release tree, and the Vendor_Release_Tag        #
  19. # is the symbolic tag for this release.                      #
  20. #                                        #
  21. # checkin traverses the current directory, ensuring that an             #
  22. # identical directory structure exists in the repository directory.  It        #
  23. # then checks the files in in the following manner:                #
  24. #                                        #
  25. #        1) If the file doesn't yet exist, check it in             #
  26. #            as revision 1.1                        #
  27. #        2) Tag branch 1.1.1 with the vendor tag                #
  28. #        3) Check the file into the vendor branch,             #
  29. #            labeling it with the Vendor_Release_Tag            #
  30. #        4) If the file didn't previously exist,             #
  31. #            make the vendor branch the default branch        #
  32. #                                        #
  33. # The script also is somewhat verbose in letting the user know what is        #
  34. # going on.  It prints a diagnostic when it creates a new file, or updates  #
  35. # a file that has been modified on the trunk.                       #
  36. #                                        #
  37. #############################################################################
  38.  
  39. set vbose = 0
  40. set message = ""
  41. set cvsbin = /usr/local/bin
  42. set rcsbin = /usr/local/bin
  43. set grep = /bin/grep
  44. set message_file = /tmp/checkin.$$
  45. set got_one = 0
  46.  
  47. if ( $#argv < 3 ) then
  48.     echo "Usage: checkin [-v] [-m message] [-f message_file] repository"
  49.     echo "    Vendor_Tag Vendor_Release_Tag [Vendor_Release_tag...]"
  50.     exit 1
  51. endif
  52. while ( $#argv )
  53.     switch ( $argv[1] )
  54.         case -v:
  55.             set vbose = 1
  56.         breaksw
  57.     case -m:
  58.         shift
  59.         echo $argv[1] > $message_file
  60.         set got_one = 1
  61.         breaksw
  62.     case -f:
  63.         shift
  64.         set message_file = $argv[1]
  65.         set got_one = 2
  66.         breaksw
  67.     default:
  68.         break
  69.     endsw
  70.     shift
  71. end
  72. if ( $#argv < 3 ) then
  73.     echo "Usage: checkin [-v] [-m message] [-f message_file] repository"
  74.     echo "    Vendor_Tag Vendor_Release_Tag [Vendor_Release_tag...]"
  75.     exit 1
  76. endif
  77. set repository = $argv[1]
  78. shift
  79. set vendor = $argv[1]
  80. shift
  81. set release = $argv[1]
  82. shift
  83. set extra_release = ( $argv )
  84.  
  85. if ( ! $?CVSROOT ) then
  86.     echo "Please set the environmental variable CVSROOT to the root"
  87.     echo "    of the tree you wish to update"
  88.     exit 1
  89. endif
  90.  
  91. if ( $got_one == 0 ) then
  92.     echo "Please Edit this file to contain the RCS log information" >$message_file
  93.     echo "to be associated with this file (please remove these lines)">>$message_file
  94.     if ( $?EDITOR ) then
  95.     $EDITOR $message_file > /dev/tty
  96.     else
  97.     /usr/ucb/vi $message_file > /dev/tty
  98.     endif
  99.     set got_one = 1
  100. endif
  101.  
  102. umask 2
  103.  
  104. set update_dir = ${CVSROOT}/${repository}
  105. if ( -d SCCS ) then
  106.     sccs get SCCS/* >& /dev/null
  107. endif
  108. if ( -d RCS ) then
  109.     $rcsbin/co RCS/* >& /dev/null
  110. endif
  111. foreach name ( * .[a-zA-Z0-9]* )
  112.     if ( $name == SCCS ) then
  113.     continue
  114.     endif
  115.     if ( $name == RCS ) then
  116.     continue
  117.     endif
  118.     if ( $vbose ) then
  119.     echo "Updating ${repository}/${name}"
  120.     endif
  121.     if ( -d $name ) then
  122.     if ( ! -d ${update_dir}/${name} ) then
  123.         echo "WARNING: Creating new directory ${repository}/${name}"
  124.         mkdir ${update_dir}/${name}
  125.         if ( $status ) then
  126.         echo "ERROR: mkdir failed - aborting"
  127.         exit 1
  128.         endif
  129.     endif
  130.     chdir $name
  131.     if ( $status ) then
  132.         echo "ERROR: Couldn\'t chdir to $name - aborting"
  133.         exit 1
  134.     endif
  135.     if ( $vbose ) then
  136.         $cvsbin/checkin -v -f $message_file ${repository}/${name} $vendor $release $extra_release
  137.     else
  138.         $cvsbin/checkin -f $message_file ${repository}/${name} $vendor $release $extra_release
  139.     endif
  140.     if ( $status ) then
  141.         exit 1
  142.     endif
  143.     chdir ..
  144.     else
  145.     if ( ! -f $name ) then
  146.         echo "WARNING: $name is neither a regular file"
  147.         echo "       nor a directory - ignored"
  148.         continue
  149.     endif
  150.     set file = ${update_dir}/${name},v
  151.     set new = 0
  152.     set comment = ""
  153.     grep -s '\$Log.*\$' ${name}
  154.     if ( $status == 0 ) then
  155.         set myext = ${name:e}
  156.         set knownext = 0
  157.         foreach xx ( "c" "csh" "e" "f" "h" "l" "mac" "me" "mm" "ms" "p" "r" "red" "s" "sh" "sl" "cl" "ml" "el" "tex" "y" "ye" "yr" "" )
  158.         if ( "${myext}" == "${xx}" ) then
  159.             set knownext = 1
  160.             break
  161.         endif
  162.         end
  163.         if ( $knownext == 0 ) then
  164.         echo For file ${file}:
  165.         grep '\$Log.*\$' ${name}
  166.         echo -n "Please insert a comment leader for file ${name} > "
  167.         set comment = $<
  168.         endif
  169.     endif
  170.     if ( ! -f $file ) then
  171.         if ( ! -f ${update_dir}/Attic/${name},v ) then
  172.             echo "WARNING: Creating new file ${repository}/${name}"
  173.         if ( "${comment}" != "" ) then
  174.             $rcsbin/rcs -q -i -c"${comment}" -t/dev/null $file
  175.         endif
  176.             $rcsbin/ci -q -u1.1 -t/dev/null $file
  177.             if ( $status ) then
  178.             echo "ERROR: Initial check-in of $file failed - aborting"
  179.             exit 1
  180.             endif
  181.             set new = 1
  182.         else
  183.         set file = ${update_dir}/Attic/${name},v
  184.         echo "WARNING: Updating ${repository}/Attic/${name}"
  185.             set headbranch = `sed -n '/^head/p; /^branch/p; 2q' $file`
  186.             if ( $#headbranch != 2 && $#headbranch != 4 ) then
  187.             echo "ERROR: corrupted RCS file $file - aborting"
  188.             endif
  189.         set head = "$headbranch[2]"
  190.         set branch = ""
  191.         if ( $#headbranch == 4 ) then
  192.             set branch = "$headbranch[4]"
  193.         endif
  194.             if ( "$head" == "1.1;" && "$branch" != "1.1.1;" ) then
  195.             ${rcsbin}/rcsdiff -q -r1.1 $file > /dev/null
  196.             if ( ! $status ) then
  197.                 set new = 1
  198.             endif
  199.             else
  200.                 if ( "$branch" != "1.1.1;" ) then
  201.                 echo -n "WARNING: Updating locally modified file "
  202.             echo    "${repository}/Attic/${name}"
  203.                 endif
  204.             endif
  205.         endif
  206.     else
  207.         set headbranch = `sed -n '/^head/p; /^branch/p; 2q' $file`
  208.         if ( $#headbranch != 2 && $#headbranch != 4 ) then
  209.         echo "ERROR: corrupted RCS file $file - aborting"
  210.         endif
  211.         set head = "$headbranch[2]"
  212.         set branch = ""
  213.         if ( $#headbranch == 4 ) then
  214.         set branch = "$headbranch[4]"
  215.         endif
  216.         if ( "$head" == "1.1;" && "$branch" != "1.1.1;" ) then
  217.         ${rcsbin}/rcsdiff -q -r1.1 $file > /dev/null
  218.         if ( ! $status ) then
  219.             set new = 1
  220.         endif
  221.         else
  222.             if ( "$branch" != "1.1.1;" ) then
  223.             echo -n "WARNING: Updating locally modified file "
  224.             echo    "${repository}/${name}"
  225.             endif
  226.         endif
  227.     endif
  228.     $rcsbin/rcs -q -N${vendor}:1.1.1 $file
  229.     if ( $status ) then
  230.         echo "ERROR: Attempt to set Vendor_Tag in $file failed - aborting"
  231.         exit 1
  232.     endif
  233.     set lock_failed = 0
  234.     $rcsbin/rcs -q -l${vendor} $file >& /dev/null
  235.     if ( $status ) then
  236.         set lock_failed = 1
  237.     endif
  238.     if ( "${comment}" != "" ) then
  239.         $rcsbin/rcs -q -c"${comment}" $file
  240.     endif
  241.     $rcsbin/ci -q -f -u${vendor} -N${release} $file < $message_file
  242.     if ( $status ) then
  243.         echo "ERROR: Check-in of $file failed - aborting"
  244.         if ( ! $lock_failed ) then
  245.             $rcsbin/rcs -q -u${vendor} $file
  246.         endif
  247.         exit 1
  248.     endif
  249.     foreach tag ( $extra_release )
  250.         $rcsbin/rcs -q -N${tag}:${release} $file
  251.         if ( $status ) then
  252.         echo "ERROR: Couldn't add tag $tag to file $file"
  253.         continue
  254.         endif
  255.     end
  256.     if ( $new ) then
  257.         $rcsbin/rcs -q -b${vendor} $file
  258.         if ( $status ) then
  259.         echo "ERROR: Attempt to change default branch failed - aborting"
  260.         exit 1
  261.         endif
  262.     endif
  263.     endif
  264. end
  265. if ( $got_one == 1 ) rm $message_file
  266.