#-------------------------------------------------- # # $Id: backdiff,v 1.2 2008/01/02 10:29:44 erwlem Exp $ # # description: see usage() # # 071128 ele Started # 080102 ele Support crossing branches # #-------------------------------------------------- #-------------------------------------------------- # # get_prev_rev - take a cvs revision number and return the previous revision # PREVREV= get_prev_rev() { REV=$1 BRANCH= if [ `echo $REV | grep "\.1$" | wc -l` -eq "1" ]; then # truncate the last 2 digits to get the previous version PREVREV=`echo $REV | sed -e "s/\.[0-9]*\.1*$//"` # this works even if we REV=1.1 else # split the current revision in a header part, specific to the current branch, # and a tailing number, specific to this file in the branch while [ `echo $REV | grep '\.' | wc -l` -ne "0" ]; do BRANCH=$BRANCH`echo $REV | sed -e "s/\..*//"`"." REV=`echo $REV | sed -e "s/^[0-9]*\.//"` done # then decrease REV... let BACKREV="$REV - 1" if [ $BACKREV -lt 1 ]; then BACKREV=1 fi PREVREV=$BRANCH$BACKREV fi } #-------------------------------------------------- # # usage blurb # usage() { cat < -h help -c N diff changes over the last N commits of file Example: # shows changes made during the last commit of essordgen.pl $ backdiff essordgen.pl # shows changes made since the 4th last commit of essordgen.pl $ backdiff -c 4 essordgen.pl EOF } #-------------------------------------------------- # # main # #-------------------------------------------------- BACKCOMMIT=1 while getopts ":hc:" OPTION; do case $OPTION in h) usage; exit;; c) BACKCOMMIT=$OPTARG;; *) echo "ERROR: unexpected argument. type -h for usage." exit;; esac done # get the file name shift $(($OPTIND - 1)) FILE=$1 # is the file valid? if [ -z $FILE ]; then echo "ERROR: your must provide a file name. type -h for usage." exit fi if [ ! -z $2 ]; then echo "ERROR: file name [$FILE] should not be followed by any argument. type -h for usage." exit fi if [ ! -f $FILE ]; then echo "ERROR: file [$FILE] does not exist or is not a file." exit fi # is the file up to date? if [ `cvs status $FILE | grep "Up-to-date" | wc -l` -ne "1" ]; then echo "ERROR: [$FILE] is not in the cvs or is not up-to-date" exit fi # what is the file's current cvs version? CURREV=`cvs status $FILE | grep "Working revision" | cut -d ':' -f 2 | sed -e "s/[ \t]//g"` # now step back through revisions, one commit at a time TMPREV=$CURREV PREVREV=$CURREV while [ $BACKCOMMIT -ne 0 ]; do get_prev_rev $TMPREV TMPREV=$PREVREV let BACKCOMMIT="$BACKCOMMIT - 1" done # show diff cvs diff -r $PREVREV -r $CURREV $FILE