programming

svn diff wrapper for diff(1) and tkdiff

Posted by mitch on June 27, 2012
software

I have been a big fan of xxdiff for many years–so much so that I wrote a Mac GUI clone for it as a mental exercise while on vacation in 2006. Unfortunately, xxdiff with svn has always sucked–it requires awkward scripts to plug it into svn, and those don’t tie into ‘svn diff –diff-cmd ‘ very well. A buddy recommended I switch to tkdiff, and it’s not bad at all. This morning I threw together a wrapper to point my ~/.subversion/config at for 2 file diffs. Since I do a lot of work in both SSH and in X11 terminals, I wanted something that could relieve me of typing ‘–diff-cmd diff’ all day long.

#!/bin/bash
#
# Script to enable 'svn diff' as a GUI diff in X11 or a CLI diff
# on the command line (or if stdout is redirected).
#
# I couldn't get tkdiff to take a -geometry argument. I ended up
# setting my geometry in tkdiff's opts dictionary.
#
# Arguments coming in from svn diff:
#
# -u -L src/hello.cpp (revision 1234) -L src/hello.cpp (working copy) src/.svn/text-base/hello.cpp.svn-base src/hello.cpp
#

dash_u=$1
label1="$2 $3"
label2="$4 $5"
file1="$6"
file2="$7"
# echo "Comparing _$6_ and _$7_"
cmd=diff
if [ -t 1 -a -n "$DISPLAY" ]; then
    cmd=tkdiff
fi

$cmd "$label1" "$label2" "$file1" "$file2" 
RC=$?

exit $RC

Tags: , ,