3 # cvs2vendor - move revsisions from files in A to files in B
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
13 # This script is also a decent example of repository maintenance using
14 # raw RCS commands (if I do say so myself! ;-).
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.
21 # Extra branches in the source directory will cause breakage.
23 # Intermediate files are created in the current working directory
24 # where this script is started.
26 # Written by Greg A. Woods <woods@planix.com>, based on rcs2sccs
27 # (retains some of the rlog parsing from it).
29 # The copyright is in the Public Domain.
33 echo USAGE: $0 srcdir dstdir
39 revfile=/tmp/cvs2vendor_$$_rev
42 commentfile=/tmp/cvs2vendor_$$_comment
45 if sort -k 1,1 /dev/null 2>/dev/null
46 then sort_each_field='-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9'
47 else sort_each_field='+0 +1 +2 +3 +4 +5 +6 +7 +8'
50 srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
52 # the "" is a trick to get $tsrcdir itself without resorting to '.'
53 for ldir in "" $srcdirs; do
58 # Loop over every RCS file in srcdir
60 for vfile in $srcdir/*,v; do
61 # get rid of the ",v" at the end of the name
62 file=`echo $vfile | sed -e 's/,v$//'`
63 bfile=`basename $file`
65 if [ ! -d $dstdir ]; then
66 echo "making locally added directory $dstdir"
69 if [ ! -f $dstdir/$bfile,v ]; then
70 echo "copying locally added file $dstdir/$bfile ..."
75 # work on each rev of that file in ascending order
76 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
78 for rev in `cat $revfile`; do
82 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//'`
83 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//'`
84 sed "s/$olddate/$newdate/" < $dstdir/$bfile,v > $dstdir/$bfile.x
85 mv -f $dstdir/$bfile.x $dstdir/$bfile,v
86 chmod -w $dstdir/$bfile,v
87 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)}'`
88 if [ -n "$symname" ]; then
89 echo "tagging $file with $symname ..."
90 rcs $symname $dstdir/$bfile,v
92 echo ERROR - rcs $symname $dstdir/$bfile,v
96 continue # skip first rev....
100 # get a lock on the destination local branch tip revision
101 co -r1 -l $dstdir/$bfile
103 echo ERROR - co -r1 -l $dstdir/$bfile
108 # get file into current dir and get stats
109 date=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s %s\n",$2,$3); exit}' | sed -e 's/;//'`
110 author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
112 symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
114 rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
116 echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
118 co -p -r$rev $file > $bfile
120 echo ERROR - co -p -r$rev $file
124 # check file into vendor repository...
125 ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
127 echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
132 # set the default branch to the trunk...
133 # XXX really only need to do this once....
134 rcs -b1 $dstdir/$bfile
136 echo ERROR - rcs -b1 $dstdir/$bfile
145 echo " Conversion Completed Successfully"