You are here: News
Akatombo Media logo
English 日本語

Akatombo Web Log

Thursday, April 27, 2006

Ignore whitespace in a Subversion diff

Doing some work on a software project, in which part of the modifications I’m doing involve changing the indents on the code to make it conform to the coding conventions I follow and make it easier to easily read the code at a glance.  When I have finished doing that though, I want to go back and make sure I haven’t inadvertently screwed something up in the actual code while I was changing the spacing.

svn diff doesn’t have a built in option for ignoring whitespace, but gnu diff does, so we use that.

to use a different diff command us the --diff-cmd parameter to svn diff, and to pass options to that command use the -x parameter.

If I was going to run the command in gnu diff directly I would use diff -uw /path/to/file1 /path/to/file2

In svn I want to diff against the latest version in the working copy (BASE) so I only need to pass in the file to diff and no revision info

Here is the command:

svn diff --diff-cmd diff -x -uw /path/to/file

Now at some point I have to see if I can figure out how to hack the subversion bundle for textmate to make that option available to me in the nice html highlighted view.

Posted by UltraBob on 04/27 at 07:29 PM
8 Comments | No Trackbacks | Permanent Link

  1. Posted by Hugo Salgado

    Thanks UtraBob. I was trying to obtain the same behaviour.
    But do you know how to make it the default diff command inside subversion? I tried to use the ‘diff-cmd’ helper line in ~/.subversion/config file, but it don’t allow to pass the extra arguments to diff.

    Finally i’m using a workaround… using a shell script that calls the external diff with the correct parameters -uw, and in .subversion/config i use this shell script as diff-cmd :(

    July 4th, 2006 11:18 PM


  2. Posted by UltraBob

    Wow this comment is almost exactly a year old, but I don’t remember seeing it when it came in.  Sorry for having not replied.  Did you ever figure out how to make that the default behavior because I don’t know off the top of my head.

    July 9th, 2007 10:08 PM


  3. Posted by Matt

    You can set the TextMate environment variable (in Preferences/Advanced) and add whichever option(s) you’d like passed to the diff command:

    TM_SVN_DIFF_CMD --> diff --extensions “-b -u”

    September 8th, 2007 03:07 AM


  4. Posted by steveo

    I simply made a bash shell alias to use when I want to use this command:

    alias svndw=’svn diff --diff-cmd diff -x -uw’

    September 12th, 2007 11:43 PM


  5. Posted by UltraBob

    Good call!  That has given me an idea for a bunch of other things I’m working on at the moment.  Amazing how something like that can awaken a ton of neural pathways and start one off in a completely new direction.

    September 12th, 2007 11:51 PM


  6. Posted by steveo

    Cool beans.  Sometimes it’s the simple stuff.

    September 12th, 2007 11:58 PM


  7. Posted by Joe Maller

    Matt’s settings from comment #3 worked almost perfectly for me. I ended up with the following:

    TM_SVN_DIFF_CMD -> /usr/bin/diff --extensions “-bu”

    For whatever reason, the ‘-u’ was showing up as a commit file in TextMate.

    Remember to check for curly quotes.

    April 9th, 2008 04:24 AM


  8. Posted by rocko

    What about
    svn diff -x [-u | -b | -w | --ignore-eol-style]
    The diff engine internal to Subversion can now ignore whitespace and eol-style when computing the diff.

    (since subversion 1.4)

    May 29th, 2008 04:06 PM


Commenting is not available in this weblog entry.