#!/bin/sh ######################################################################### # # FILE : cvsundo # DATE : 10.07.2001 # AUTHOR : Patrick Meier / patrick.meier@profidatagroup.com # DESCRIPTION : undo the changes # # Copyrigth (C) 2001 by Patrick Meier, Switzerland # ######################################################################### PN=`basename "$0"` CVS=/usr/local/bin/cvs-1.11.1p1-SUNOS-5.6 CVSBIN="`echo \"$CVS\" | sed 's/.*\/.*\///g'`" CVSPARAMETER= STARTSTRING="==>" export CVS ######################################################################### # getCVSHelp ######################################################################### getCVSHelp() { tag="$1" help="`$CVS $tag --help 2>&1 \ | sed \"s/$tag: invalid option -- -//g\" \ | sed 's/diff: unrecognized option \`--help//g;' \ | sed \"s/Usage:*//g\" \ | sed \"s/$CVSBIN $tag //g\" \ | sed \"s/-d/-dir/g\" \ | sed \"s/\'//g\" \ | sed \"s/(Specify the --help global option for a list of other help options)//g\"`" command="`echo $help | sed \"s/\[files.*/ \[files\.\.\.\]/\"`" description="`echo "$help" | sed \"s/.*\[.*\]//g\"`" echo $command echo "$description" } ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - undo changes" printf "usage: $PN [-d cvs-root] " getCVSHelp unedit exit 1 } ######################################################################### # ParameterFailed ######################################################################### ParameterFailed() { echo "${STARTSTRING}Parameter faild: $1 ..."; echo "" Usage } ######################################################################### # cutEndSlash ######################################################################### cutEndSlash() { echo $@ | awk ' { text=$0; while( substr( text, length(text),1 ) == "/" ) { text=substr( text, 1, length(text)-1 ); } print text; }' } ######################################################################### # cutEndSlash ######################################################################### getFileName() { echo $@ | awk ' { text=$0; while( substr(text, length( text ),1) == "/" ) { text=substr(text, 1, length(text)-1 ); } for( i=length( text ); i>=1; i-- ) { if( substr( text, i,1) == "/" ) { text=substr( text, i+1, length( text )-i ); break; } } print text; }' } ######################################################################### # complete a given path # tested with: # completePath ../../kkk.c # completePath ../././kkk.c # completePath dsd/dd/dd.c # completePath ../../kkk.c /home/hh/dd/ ######################################################################### completePath() { if [ -z "$2" ] then initPath=`pwd` else initPath=`cutEndSlash $2` fi echo "$initPath $1" | awk ' { mainPath=$1 i=0; backPath=0; num=split( $2, separatedText, "/" ); numMainPath=split( $1, mainPathSeparated, "/" ); fileName="" for( i=1; i <=num; i++ ) { if( separatedText[ i ] == ".." ) backPath++; } for( i=1; i<=numMainPath-backPath; i++ ) { if( length( fileName )==0 ) fileName=mainPathSeparated[ i ]; else fileName=fileName"/"mainPathSeparated[ i ]; } for( i=backPath+1; i<=num; i++ ) { if( separatedText[ i ] != "." ) { if( length( fileName )==0 ) fileName=separatedText[ i ]; else fileName=fileName"/"separatedText[ i ]; } } print "/"fileName }' } ######################################################################### # get all cvs editors ######################################################################### getOwnerOfLockedFiles() { fileToEdit="`completePath $1`" cvsLine=`$CVS editors | grep "$1" | awk '{print $2" "$1}'` if [ -z "$cvsLine" ] then return else lockedUser="`echo $cvsLine | awk '{print $1}'`" cvsFileName="`echo $cvsLine | awk '{print $2}'`" cvsFullName=`completePath $cvsFileName` #echo "<$lockedUser> <$cvsFileName> <$cvsFullName>" fi if [ "$fileToEdit" = "$cvsFullName" ] then echo $lockedUser fi } ######################################################################### # cvs - undo ######################################################################### doCVSUndo() { printf "${STARTSTRING}Undoing changes of file $1: version " $CVS admin -q -u $1 if [ -r $i ] then : else update="`$CVS update -A -C $1`" if [ -n "$update" ] then echo "${STARTSTRING}Updating the file $1 from cvs: "$update else echo "${STARTSTRING}File $i not found! ($update)" exit fi fi $CVS unedit $1 } ######################################################################### # main ######################################################################### while [ $# -gt 0 ] do case "$1" in -d) if [ $# -gt 1 ] ; then CVSROOT="$2"; shift; else ParameterFailed $1; fi;; -h) Usage; exit 1;; -help) Usage; exit 1;; --help) Usage; exit 1;; -*) CVSPARAMETER="$1 $CVSPARAMETER";; *) break;; esac shift done if [ $# -lt 1 ] then Usage else user="`who am i | awk '{print $1}'`" for i in $@ do #if [ -r $i ] #then lockedUser="`getOwnerOfLockedFiles $i`" if [ -z "$lockedUser" ] then echo "${STARTSTRING}You do not have locked the file $i!" else if [ "$user" = "$lockedUser" ] then doCVSUndo $i else echo "${STARTSTRING}You do not have locked the file $i! User $lockedUser is editing the file!" fi fi #else # echo "${STARTSTRING}File $i not found!" #fi done fi ######################################################################### # EOF #########################################################################