#!/bin/sh ######################################################################### # # FILE : cvscommit # DATE : 10.07.2001 # AUTHOR : Patrick Meier / patrick.meier@profidatagroup.com # DESCRIPTION : commit and unlock files from the cvs # # 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="==>" comment="" export CVS ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - commit and unlock files from the cvs" #echo "usage: $PN [-d cvs-root] [-f] [-r revision] file..." echo "usage: $PN [-d cvs-root] [-f] file..." 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 - commit ######################################################################### doCVSCommit() { message="${STARTSTRING}Please enter a comment to file $1:" while [ -z "$comment" ] do printf "$message" read comment done printf "${STARTSTRING}Commit the file $1 to the cvs and unlock it: version " $CVS admin -q -u $1 cmd="`$CVS commit $CVSPARAMETER -m \"$comment\" $1`" #if [ "`echo \"$CVSPARAMETER\" | sed 's/-r//'`" = "$CVSPARAMETER" ] #then # : #else # echo "-r parameter found" # cvsupdate -A $1 #fi if [ -z "$cmd" ] then echo "${STARTSTRING}Nothing has changed! Use cvsundo to unlock the file $1" else echo "${STARTSTRING}$cmd" fi } ######################################################################### # main ######################################################################### while [ $# -gt 0 ] do case "$1" in -d) if [ $# -gt 1 ] ; then CVSROOT="$2"; shift; else ParameterFailed $1; fi;; # -r) if [ $# -gt 1 ] ; then echo "\n\n==>This option was disabled by Patrick Meier<==!\n\n"; exit; else ParameterFailed $1; fi;; -r) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -m) if [ $# -gt 1 ] ; then comment="$2"; shift; else ParameterFailed $1; fi;; -f) CVSPARAMETER="$1 $CVSPARAMETER";; -h) Usage; exit 1;; -help) Usage; exit 1;; --help) Usage; exit 1;; -*) Usage; exit 1;; *) break;; esac shift done user="`who am i | awk '{print $1}'`" if [ $# -lt 1 ] then Usage else 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 doCVSCommit $i else echo "${STARTSTRING}You ($user) 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 #########################################################################