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 32if [ $# -ne 2 ]; then 33 echo USAGE: $0 srcdir dstdir 34 exit 2 35fi 36tsrcdir=$1 37tdstdir=$2 38 39revfile=/tmp/cvs2vendor_$$_rev 40rm -f $revfile 41 42commentfile=/tmp/cvs2vendor_$$_comment 43rm -f $commentfile 44 45srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'` 46 47# the "" is a trick to get $tsrcdir itself without resorting to '.' 48for ldir in "" $srcdirs; do 49 50 srcdir=$tsrcdir/$ldir 51 dstdir=$tdstdir/$ldir 52 53 # Loop over every RCS file in srcdir 54 # 55 for vfile in $srcdir/*,v; do 56 # get rid of the ",v" at the end of the name 57 file=`echo $vfile | sed -e 's/,v$//'` 58 bfile=`basename $file` 59 60 if [ ! -d $dstdir ]; then 61 echo "making locally added directory $dstdir" 62 mkdir -p $dstdir 63 fi 64 if [ ! -f $dstdir/$bfile,v ]; then 65 echo "copying locally added file $dstdir/$bfile ..." 66 cp $vfile $dstdir 67 continue; 68 fi 69 70 # work on each rev of that file in ascending order 71 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 72 73 for rev in `cat $revfile`; do 74 75 case "$rev" in 76 1.1) 77 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//'` 78 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//'` 79 sed "s/$olddate/$newdate/" < $dstdir/$bfile,v > $dstdir/$bfile.x 80 mv -f $dstdir/$bfile.x $dstdir/$bfile,v 81 chmod -w $dstdir/$bfile,v 82 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)}'` 83 if [ -n "$symname" ]; then 84 echo "tagging $file with $symname ..." 85 rcs $symname $dstdir/$bfile,v 86 if [ $? != 0 ]; then 87 echo ERROR - rcs $symname $dstdir/$bfile,v 88 exit 1 89 fi 90 fi 91 continue # skip first rev.... 92 ;; 93 esac 94 95 # get a lock on the destination local branch tip revision 96 co -r1 -l $dstdir/$bfile 97 if [ $? != 0 ]; then 98 echo ERROR - co -r1 -l $dstdir/$bfile 99 exit 1 100 fi 101 rm -f $dstdir/$bfile 102 103 # get file into current dir and get stats 104 date=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s %s\n",$2,$3); exit}' | sed -e 's/;//'` 105 author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'` 106 107 symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'` 108 109 rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile 110 111 echo "==> file $file, rev=$rev, date=$date, author=$author $symname" 112 113 co -p -r$rev $file > $bfile 114 if [ $? != 0 ]; then 115 echo ERROR - co -p -r$rev $file 116 exit 1 117 fi 118 119 # check file into vendor repository... 120 ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v 121 if [ $? != 0 ]; then 122 echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v 123 exit 1 124 fi 125 rm -f $bfile 126 127 # set the default branch to the trunk... 128 # XXX really only need to do this once.... 129 rcs -b1 $dstdir/$bfile 130 if [ $? != 0 ]; then 131 echo ERROR - rcs -b1 $dstdir/$bfile 132 exit 1 133 fi 134 done 135 done 136done 137 138echo cleaning up... 139rm -f $commentfile 140echo " Conversion Completed Successfully" 141 142exit 0 143