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