Better comment for chdir_verify_path()
[dragonfly.git] / contrib / cvs-1.12.11 / contrib / cvs2vendor.sh
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
32 if [ $# -ne 2 ]; then
33         echo USAGE: $0 srcdir dstdir
34         exit 2
35 fi
36 tsrcdir=$1
37 tdstdir=$2
38
39 revfile=/tmp/cvs2vendor_$$_rev
40 rm -f $revfile
41
42 commentfile=/tmp/cvs2vendor_$$_comment
43 rm -f $commentfile
44
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'
48 fi
49
50 srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
51
52 # the "" is a trick to get $tsrcdir itself without resorting to '.'
53 for ldir in "" $srcdirs; do
54
55         srcdir=$tsrcdir/$ldir
56         dstdir=$tdstdir/$ldir
57
58         # Loop over every RCS file in srcdir
59         #
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`
64
65                 if [ ! -d $dstdir ]; then
66                         echo "making locally added directory $dstdir"
67                         mkdir -p $dstdir
68                 fi
69                 if [ ! -f $dstdir/$bfile,v ]; then
70                         echo "copying locally added file $dstdir/$bfile ..."
71                         cp $vfile $dstdir
72                         continue;
73                 fi
74
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
77
78                 for rev in `cat $revfile`; do
79
80                         case "$rev" in
81                         1.1)
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
91                                         if [ $? != 0 ]; then
92                                                 echo ERROR - rcs $symname $dstdir/$bfile,v
93                                                 exit 1
94                                         fi
95                                 fi
96                                 continue                        # skip first rev....
97                                 ;;
98                         esac
99
100                         # get a lock on the destination local branch tip revision
101                         co -r1 -l $dstdir/$bfile
102                         if [ $? != 0 ]; then
103                                 echo ERROR - co -r1 -l $dstdir/$bfile
104                                 exit 1
105                         fi
106                         rm -f $dstdir/$bfile
107
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/;//'`
111
112                         symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[         ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
113
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
115
116                         echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
117
118                         co -p -r$rev $file > $bfile
119                         if [ $? != 0 ]; then
120                                 echo ERROR - co -p -r$rev $file
121                                 exit 1
122                         fi
123
124                         # check file into vendor repository...
125                         ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
126                         if [ $? != 0 ]; then
127                                 echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
128                                 exit 1
129                         fi
130                         rm -f $bfile
131
132                         # set the default branch to the trunk...
133                         # XXX really only need to do this once....
134                         rcs -b1 $dstdir/$bfile
135                         if [ $? != 0 ]; then
136                                 echo ERROR - rcs -b1 $dstdir/$bfile
137                                 exit 1
138                         fi
139                 done
140         done
141 done
142
143 echo cleaning up...
144 rm -f $commentfile
145 echo "       Conversion Completed Successfully"
146
147 exit 0