#!/usr/bin/env bash # # File : svndiff # Author : Matthias Hüsken # Purpose : A wrapper to call an arbitrary diff-program in a subversion # working copy. Reads the environment variable SVN_DIFF which # the user can use to specify his/her favourite diff-program # (like diff, mgdiff, tkdiff etc.). The current version in the # working copy is compared to the version in the HEAD revision. # # Script will most probably become obsolete as soon as the # subversion APIs for external diff'ing are released. # # Requirements for the script to run properly: # - bash :-) # - mktemp in $PATH # - svn in $PATH # - write access to /tmp # - a diff program that is called via # DIFF_PROG file1 file2 # - probably a subversion repository... # # if the SVN_DIFF environment variable is not set, fall back to the diff # program specified here DIFF_PROG=mgdiff TMPFILE="" # remove tmp-file and leave program function cleanup () { # remove the tempfile if [ -f $TMPFILE ] then rm -rf $TMPFILE fi # look for return value if [ $# -le 1 ] then VAL=1 else VAL=$1 fi # leave program exit $1 } # if no arg is given, display usage info and exit if [ $# -ne 1 ] then echo "Usage is: $0 FILE" cleanup 1 fi # create temp file TMPFILE=`mktemp -q /tmp/svntmp.XXXXXX` if [ $? -ne 0 -o ! -f $TMPFILE ] then echo "Couldn't create temp file..." cleanup 1 fi # look for diff program DIFF="unknown" # first try $SVN_DIFF if [ ! -z $SVN_DIFF ] then DIFF=`which $SVN_DIFF 2> /dev/null || echo unknown` SEARCHED=$SVN_DIFF fi # if we found the prog, everything's fine # otherwise look for prog specified above... if [ $DIFF == "unknown" ] then DIFF=`which $DIFF_PROG 2> /dev/null || echo unknown` if [ ! ${SEARCHED}x = x ]; then SEARCHED="$SEARCHED or "; fi SEARCHED="$SEARCHED$DIFF_PROG" # if we still coudn't find a diff, exit if [ $DIFF == "unknown" ] then echo "Couldn't find $SEARCHED, is it installed and in \$PATH?" cleanup 2 fi fi echo "using diff: $DIFF" # look for svn SVN=`which svn 2> /dev/null || echo unknown` # if we can't find it, exit if [ $SVN == "unknown" ] then echo "Couldn't find svn, is it installed and in \$PATH?" cleanup 3 fi # test if the desired file exists if [ ! -r $1 ] then echo "File $1 doesn't exist..." cleanup 4 fi # get file from latest svn HEAD revision $SVN cat $1 >> $TMPFILE RETVAL=$? # if we successfully retrieved the file, do the actual diff if [ $RETVAL -eq 0 ] then $DIFF $1 $TMPFILE fi # if we were not successful retrieving the file from svn, exit if [ $RETVAL -ne 0 ] then echo "Couldn't retrieve HEAD revision from svn..." cleanup 5 fi