Try to fixup the mess of mdoc(7)/man(7) mixture as created by the merge.
[netbsd-mini2440.git] / external / gpl2 / xcvs / dist / contrib / cvs2vendor.sh
blob166544d926a61223ffc6849d78db5bb87db42691
1 #! /bin/sh
3 # Copyright (C) 1997-2005 The Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # cvs2vendor - move revsisions from files in A to files in B
17 # The primary reason for this script is to move deltas from a
18 # non-vendor branched repository onto a fresh vendor branched one,
19 # skipping the initial checkin in assumption that it is the same in
20 # both repositories. This way you can take a project that was moved
21 # into CVS without the benefit of the vendor branch and for all
22 # intents and purposes add the vendor branch underneath the existing
23 # deltas.
25 # This script is also a decent example of repository maintenance using
26 # raw RCS commands (if I do say so myself! ;-).
28 # Tags are preserved.
30 # The timestamp of the initial vendor branch revision will be adjusted
31 # to be the same as the 1.1 revision of each source file.
33 # Extra branches in the source directory will cause breakage.
35 # Intermediate files are created in the current working directory
36 # where this script is started.
38 # Written by Greg A. Woods <woods@planix.com>, based on rcs2sccs
39 # (retains some of the rlog parsing from it).
41 # The copyright is in the Public Domain.
44 if [ $# -ne 2 ]; then
45 echo USAGE: $0 srcdir dstdir
46 exit 2
48 tsrcdir=$1
49 tdstdir=$2
51 revfile=/tmp/cvs2vendor_$$_rev
52 rm -f $revfile
54 commentfile=/tmp/cvs2vendor_$$_comment
55 rm -f $commentfile
57 if sort -k 1,1 /dev/null 2>/dev/null
58 then sort_each_field='-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9'
59 else sort_each_field='+0 +1 +2 +3 +4 +5 +6 +7 +8'
62 srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
64 # the "" is a trick to get $tsrcdir itself without resorting to '.'
65 for ldir in "" $srcdirs; do
67 srcdir=$tsrcdir/$ldir
68 dstdir=$tdstdir/$ldir
70 # Loop over every RCS file in srcdir
72 for vfile in $srcdir/*,v; do
73 # get rid of the ",v" at the end of the name
74 file=`echo $vfile | sed -e 's/,v$//'`
75 bfile=`basename $file`
77 if [ ! -d $dstdir ]; then
78 echo "making locally added directory $dstdir"
79 mkdir -p $dstdir
81 if [ ! -f $dstdir/$bfile,v ]; then
82 echo "copying locally added file $dstdir/$bfile ..."
83 cp $vfile $dstdir
84 continue;
87 # work on each rev of that file in ascending order
88 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
90 for rev in `cat $revfile`; do
92 case "$rev" in
93 1.1)
94 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//'`
95 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//'`
96 sed "s/$olddate/$newdate/" < $dstdir/$bfile,v > $dstdir/$bfile.x
97 mv -f $dstdir/$bfile.x $dstdir/$bfile,v
98 chmod -w $dstdir/$bfile,v
99 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)}'`
100 if [ -n "$symname" ]; then
101 echo "tagging $file with $symname ..."
102 rcs $symname $dstdir/$bfile,v
103 if [ $? != 0 ]; then
104 echo ERROR - rcs $symname $dstdir/$bfile,v
105 exit 1
108 continue # skip first rev....
110 esac
112 # get a lock on the destination local branch tip revision
113 co -r1 -l $dstdir/$bfile
114 if [ $? != 0 ]; then
115 echo ERROR - co -r1 -l $dstdir/$bfile
116 exit 1
118 rm -f $dstdir/$bfile
120 # get file into current dir and get stats
121 date=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s %s\n",$2,$3); exit}' | sed -e 's/;//'`
122 author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
124 symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[ ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
126 rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
128 echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
130 co -p -r$rev $file > $bfile
131 if [ $? != 0 ]; then
132 echo ERROR - co -p -r$rev $file
133 exit 1
136 # check file into vendor repository...
137 ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
138 if [ $? != 0 ]; then
139 echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
140 exit 1
142 rm -f $bfile
144 # set the default branch to the trunk...
145 # XXX really only need to do this once....
146 rcs -b1 $dstdir/$bfile
147 if [ $? != 0 ]; then
148 echo ERROR - rcs -b1 $dstdir/$bfile
149 exit 1
151 done
152 done
153 done
155 echo cleaning up...
156 rm -f $commentfile
157 echo " Conversion Completed Successfully"
159 exit 0