Subversion diff commands

Subversion allows to use a custom command for displaying diffs using svn diff --diff-cmd <cmd>. I have been using diff-cmd=colordiff in my ~/.subversion/config for quite some time now. This is really useful, but occasionally I would also like to use vimdiff to get a nice side-by-side diff.

Although this sounds quite easy at first, there are some hurdles. Subversion expects the given command to adhere to the GNU diff parameters, that means it expects it to understand and parse the labels it passes before the actual filenames. This works fine for colordiff, but not vimdiff which only wants the old and new filenames.

For a better diff experience with svn, I set up the following shell function which let’s me choose the program I want to use for diffing.

First, I need a new wrapper script at ~/libexec/svndiff which takes the actual diff program as first option, ignores the GNU diff labels and calls that program passing old and new filename.

#!/bin/bash
BIN=$1
shift 5
$BIN "$@"

Then I define this shell alias in my ~/.bashrc to extend the functionality of the svn command:

function svn() {
    case "$1" in
        diff-plain)
            shift;
            `which svn` diff --diff-cmd diff $@
            ;;
        diff-color)
            shift;
            `which svn` diff --diff-cmd colordiff $@
            ;;
        diff-vim)
            shift;
            `which svn` diff --diff-cmd $HOME/libexec/svndiff -x vimdiff $@
            ;;
        diff-filemerge)
            shift;
            `which svn` diff --diff-cmd $HOME/libexec/svndiff -x opendiff $@
            ;;
        *)
            `which svn` $@
            ;;
    esac
}

Now I can choose the program I find best suited for the current task in a very simplified manner, for example svn diff-vim -c1337.

6 thoughts on “Subversion diff commands

  1. RaiulBaztepo

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language 😉
    See you!
    Your, Raiul Baztepo

  2. Pingback: stev.ie/ » Blog Archive

  3. Mike

    Hi – I really enjoyed this script – simplifies things quite nicely. I am new to FileMerge and was wondering if there was a way to have the output of diff-filemerge open some sort of initial screen with just a list of the files that have differences. Currently if you execute as is, you get millions of windows popping up if there are a number of files that need to be reviewed. Any help greatly appreciated as I did through FileMerge more.

  4. Rainer Müller Post author

    No, there is no way in FileMerge to produce an overview list. Subversion invokes the diff command once for each file.

    What you could do is to make svn wait for FileMerge to close instead of just opening so many windows.

    Put this shell script at ~/libexec/opendiff-wait and change the diff-filemerge line in your .bashrc accordingly:

    #!/bin/bash
    opendiff "$@" | cat

    Now only a single window will pop up and when FileMerge is closed completely (⌘+Q) svn continues with the next file.

  5. Muti Saki

    Great job. This is what I want looking for. However this only colorizes the diff command. update, status commands can be colorized by colorsvn. (Download from http://www.console-colors.de/index.php?n=ConsColors.Downloads) After the colorsvn is installed the last part of the case statement can ben replaced with

    *)
    `which colorsvn` $@
    ;;

    After all, all svn commands are colorized.

  6. Pingback: Raim » Subversion diff with vimdiff improved

Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.