/gnu/usr.bin/cvs/contrib/cvs2vendor.sh

https://github.com/avsm/src · Shell · 142 lines · 81 code · 21 blank · 40 comment · 18 complexity · 85fd66162c211f0197796665428a2861 MD5 · raw file

  1. #! /bin/sh
  2. #
  3. # cvs2vendor - move revsisions from files in A to files in B
  4. #
  5. # The primary reason for this script is to move deltas from a
  6. # non-vendor branched repository onto a fresh vendor branched one,
  7. # skipping the initial checkin in assumption that it is the same in
  8. # both repositories. This way you can take a project that was moved
  9. # into CVS without the benefit of the vendor branch and for all
  10. # intents and purposes add the vendor branch underneath the existing
  11. # deltas.
  12. #
  13. # This script is also a decent example of repository maintenance using
  14. # raw RCS commands (if I do say so myself! ;-).
  15. #
  16. # Tags are preserved.
  17. #
  18. # The timestamp of the initial vendor branch revision will be adjusted
  19. # to be the same as the 1.1 revision of each source file.
  20. #
  21. # Extra branches in the source directory will cause breakage.
  22. #
  23. # Intermediate files are created in the current working directory
  24. # where this script is started.
  25. #
  26. # Written by Greg A. Woods <woods@planix.com>, based on rcs2sccs
  27. # (retains some of the rlog parsing from it).
  28. #
  29. # The copyright is in the Public Domain.
  30. #
  31. if [ $# -ne 2 ]; then
  32. echo USAGE: $0 srcdir dstdir
  33. exit 2
  34. fi
  35. tsrcdir=$1
  36. tdstdir=$2
  37. revfile=/tmp/cvs2vendor_$$_rev
  38. rm -f $revfile
  39. commentfile=/tmp/cvs2vendor_$$_comment
  40. rm -f $commentfile
  41. srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
  42. # the "" is a trick to get $tsrcdir itself without resorting to '.'
  43. for ldir in "" $srcdirs; do
  44. srcdir=$tsrcdir/$ldir
  45. dstdir=$tdstdir/$ldir
  46. # Loop over every RCS file in srcdir
  47. #
  48. for vfile in $srcdir/*,v; do
  49. # get rid of the ",v" at the end of the name
  50. file=`echo $vfile | sed -e 's/,v$//'`
  51. bfile=`basename $file`
  52. if [ ! -d $dstdir ]; then
  53. echo "making locally added directory $dstdir"
  54. mkdir -p $dstdir
  55. fi
  56. if [ ! -f $dstdir/$bfile,v ]; then
  57. echo "copying locally added file $dstdir/$bfile ..."
  58. cp $vfile $dstdir
  59. continue;
  60. fi
  61. # work on each rev of that file in ascending order
  62. rlog $file | grep "^revision [0-9][0-9]*\." | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
  63. for rev in `cat $revfile`; do
  64. case "$rev" in
  65. 1.1)
  66. newdate=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s.%s\n",$2,$3); exit}' | sed -e 's~/~.~g' -e 's/:/./g' -e 's/;//' -e 's/^19//'`
  67. olddate=`rlog -r1.1.1.1 $dstdir/$bfile | grep "^date: " | awk '{printf("%s.%s\n",$2,$3); exit}' | sed -e 's~/~.~g' -e 's/:/./g' -e 's/;//' -e 's/^19//'`
  68. sed "s/$olddate/$newdate/" < $dstdir/$bfile,v > $dstdir/$bfile.x
  69. mv -f $dstdir/$bfile.x $dstdir/$bfile,v
  70. chmod -w $dstdir/$bfile,v
  71. symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s:1.1.1.1\n",$1)}'`
  72. if [ -n "$symname" ]; then
  73. echo "tagging $file with $symname ..."
  74. rcs $symname $dstdir/$bfile,v
  75. if [ $? != 0 ]; then
  76. echo ERROR - rcs $symname $dstdir/$bfile,v
  77. exit 1
  78. fi
  79. fi
  80. continue # skip first rev....
  81. ;;
  82. esac
  83. # get a lock on the destination local branch tip revision
  84. co -r1 -l $dstdir/$bfile
  85. if [ $? != 0 ]; then
  86. echo ERROR - co -r1 -l $dstdir/$bfile
  87. exit 1
  88. fi
  89. rm -f $dstdir/$bfile
  90. # get file into current dir and get stats
  91. date=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s %s\n",$2,$3); exit}' | sed -e 's/;//'`
  92. author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
  93. symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
  94. rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
  95. echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
  96. co -p -r$rev $file > $bfile
  97. if [ $? != 0 ]; then
  98. echo ERROR - co -p -r$rev $file
  99. exit 1
  100. fi
  101. # check file into vendor repository...
  102. ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
  103. if [ $? != 0 ]; then
  104. echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
  105. exit 1
  106. fi
  107. rm -f $bfile
  108. # set the default branch to the trunk...
  109. # XXX really only need to do this once....
  110. rcs -b1 $dstdir/$bfile
  111. if [ $? != 0 ]; then
  112. echo ERROR - rcs -b1 $dstdir/$bfile
  113. exit 1
  114. fi
  115. done
  116. done
  117. done
  118. echo cleaning up...
  119. rm -f $commentfile
  120. echo " Conversion Completed Successfully"
  121. exit 0