#! /bin/sh set -e self=`basename $0` usage () { echo "$self: tladir cscvsdir wcvsdir" echo " tladir: tla tree tracking cvs, only totla commits there." echo " cscvsdir: cvs tree used by cscvs." echo " wcvsdir: commitable cvs tree, used to get CVS metadata." } if test $# -ne 3 ; then usage exit 1 fi cd "$1" ; tladir="$PWD" ; cd - cd "$2" ; cscvsdir="$PWD" ; cd - cd "$3" ; wcvsdir="$PWD" ; cd - yesno () { while true; do read -p "$1 [y/n]: " yn if test "$yn" != "y" -a "$yn" != "n" ; then echo 'Please type "y" or "n".' continue else if test "$yn" = "y" ; then yes="true" no="false" else yes="false" no="true" fi break fi done } gone_wrong () { echo "Something has gone wrong, bailing out." exit 1 } shell () { set +e $SHELL status=$? set -e if test $status -ne 0 ; then yesno "$SHELL exited with status $status, is there a problem?" if $yes ; then gone_wrong fi fi } cscvs_update () { cvs up -r1.1 cscvs cache -h -u } cscvs_update_and_act () { echo "*** Updating cscvs cache ***" cd "$cscvsdir" maybe_changes=false cscvs_update | while read x ; do maybe_changes=true done if $maybe_changes ; then yesno "Are there new changesets?" if $yes ; then echo "Import changes, then exit the shell to continue." cd "$cscvsdir" shell fi else echo "No changes" fi } cscvs_update_and_merge () { echo "*** Updating cscvs cache ***" cd "$cscvsdir" cscvs_update echo "Import changes, then exit the shell to continue." echo "Do NOT commit the changeset for your merge." cd "$cscvsdir" shell } cvs_update () { echo "*** Updating writeable CVS tree ***" cd "$wcvsdir" cvs up -A } # Synch wcvsdir and cscvsdir cscvs_update_and_act while true; do cvs_update cscvs_update_and_act if $no ; then break fi done remove_cvs_dirs () { tla inventory -p -d | egrep -e '(^|/)CVS$' | xargs rm -rf } # Place new CVS metadata in the totla tree cd "$cscvsdir" remove_cvs_dirs ( cd "$wcvsdir" ; find . -name CVS | tar cTf - - ) \ | ( cd "$tladir" ; tar xf - ) # Sanity: check for changes, there should not be any. check_diff () { which $1 > /dev/null # fail if command not found set +e $@ status=$? set -e if test $status -eq 1 ; then diff_found=true elif test $status -ne 0 ; then echo "$* exited with status $status" gone_wrong fi } diff_found=false cd "$tladir" echo "*** Updating revision library ***" tla library-add `tla tree-version` > /dev/null echo "*** Checking tla changes ***" check_diff tla changes echo "*** Checking cvs diff ***" check_diff cvs diff --brief if $diff_found ; then yesno "Are there any abnormal changes?" if $yes ; then gone_wrong fi fi # Merge and save logs cat /dev/null > +logfile echo 'Please merge change. Do not forget "cvs add" and "cvs remove".' echo 'Write the log in +logfile then exit the shell instead of "cvs commit".' shell cvs commit -F +logfile tar cf +arch.tar '{arch}' # Clean up totla tree tla undo -n remove_cvs_dirs # Import the merge changeset cscvs_update_and_merge cd "$tladir" tar xf +arch.tar tla commit --strict rm +arch.tar +logfile