You can specify the diff command that you want to use in Subversion using the --diff-cmd command line or by specifying it in the Subversion configuration (which is $HOME/.subversion/config for the Unix command line client).
The main thing is to understand what parameters are passed to your SVN diff command:
- 4 th for the last parameter - the name of the program on the left side
- 3 rd to the last parameter - the name of the program on the right side
- 2 nd for the last parameter - temporary file on the left side
- The last parameter is a temporary file on the right side
The first parameters passed are the keys to the Subversion diff command. For example:
You can use this information to create a script to view files in VIM. Here's a simple Perl:
#! /usr/bin/env perl use strict; use warnings; my $diff = "/usr/bin/vimdiff"; my $num_of_params = $#ARGV; my $file1 = $ARGV[$num_of_params - 1]; my $file2 = $ARGV[$num_of_params]; my $title1 = $ARGV[$num_of_params - 4]; my $title2 = $ARGV[$num_of_params - 3]; my $title = "$title1 - $title2"; $title =~ s/\t/ /g; $title =~ s/ /\\ /g; system qq($diff -c "set titlestring=$title" "$file1" "$file2");
You must ensure that your system command (e.g. vimdiff) contains the command line. I tried using mvim on my Mac, but temporary files were deleted before the mvim command was executed.
Now you can do this:
$ svn diff --diff-cmd mydiff -rPREV
And if your script is in your PATH and is executable, it should work.
Thanks ZyX
The program that accepts ZyX offers has been improved here. I had to make some changes. My diff command is actually mvim on my machine, and I need to pass two parameters ( -d to say diff, and -f say not to throw mvim in the background). This meant that passing $DIFF at the suggestion of ZyX would make my system command think that mvim -d -f is my command and I get an error message. To solve this problem, I store the command in an array. I also made the array persistent while I was on it.
Here is the program below. Modify the DIFF to point to the diff command (probably vimdiff , gvim -d -f or vim -d ). If you are on Windows and the full path is in C:/Program Files/Vim , you can use C:/Progr~1/Vim to get rid of the space. Otherwise, you will need to do:
use constant DIFF => ('C:/Program Files/Vim/VIM73/gvim', '-f', '-d')
since you cannot use qw . Can we say thanks to Microsoft for putting a space in the name of the directory where all commands are stored for no good reason? I knew you could. BTW, if the directory where your editor is located is in your PATH , you do not need to specify the full name of the directory.
#! /usr/bin/env perl use strict; use warnings; use constant DIFF => qw(mvim -d -f); my $parameters = $#ARGV; my $file1 = $ARGV[$parameters - 1]; my $file2 = $ARGV[$parameters]; my $title1 = $ARGV[$parameters - 4]; my $title2 = $ARGV[$parameters - 2]; $ENV{TITLE} = "$title1 - $title2"; system DIFF, '-c', 'let &titlestring=$TITLE', $file1, $file2;