Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / lib / cvs / contrib / cvs2vendor
blob234f4d95e5d7845416886707377a7b22f116552e
1 #! /bin/sh
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.
13 # This script is also a decent example of repository maintenance using
14 # raw RCS commands (if I do say so myself! ;-).
16 # Tags are preserved.
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.
32 if [ $# -ne 2 ]; then
33 echo USAGE: $0 srcdir dstdir
34 exit 2
36 tsrcdir=$1
37 tdstdir=$2
39 revfile=/tmp/cvs2vendor_$$_rev
40 rm -f $revfile
42 commentfile=/tmp/cvs2vendor_$$_comment
43 rm -f $commentfile
45 srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
47 # the "" is a trick to get $tsrcdir itself without resorting to '.'
48 for ldir in "" $srcdirs; do
50 srcdir=$tsrcdir/$ldir
51 dstdir=$tdstdir/$ldir
53 # Loop over every RCS file in srcdir
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`
60 if [ ! -d $dstdir ]; then
61 echo "making locally added directory $dstdir"
62 mkdir -p $dstdir
64 if [ ! -f $dstdir/$bfile,v ]; then
65 echo "copying locally added file $dstdir/$bfile ..."
66 cp $vfile $dstdir
67 continue;
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
73 for rev in `cat $revfile`; do
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
91 continue # skip first rev....
93 esac
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
101 rm -f $dstdir/$bfile
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/;//'`
107 symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
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
111 echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
113 co -p -r$rev $file > $bfile
114 if [ $? != 0 ]; then
115 echo ERROR - co -p -r$rev $file
116 exit 1
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
125 rm -f $bfile
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
134 done
135 done
136 done
138 echo cleaning up...
139 rm -f $commentfile
140 echo " Conversion Completed Successfully"
142 exit 0