16
votes

Following a blog, I created a batch file, wm.bat:

"d:\svnroot\external\winmerge\WinMerge.exe" /B /WAIT "d:\svnroot\external\winmerge\WinMergeU.exe" /e /ub /dl %3 /dr %5 %6 %7

And I tried calling

svn diff | wm

but that didn't work. So how do I integrate WinMerge or similar utility with svn diff?

Extending on David's answer below, changing the default for Windows requires editing the configuration file located at (for Windows XP)

C:\Documents and Settings\%USERNAME%\Application Data\Subversion\config

or (Windows Vista)

C:\Users\%USERNAME%\AppData\Roaming\Subversion\config
10
You should put your addition to David's answer in a comment on his answer, an edit to his answer (with a comment clearing the addition with him) or in its own answer, not in the question itself.Keith Pinson

10 Answers

32
votes

Ok, looking at the original blog post, this is what you want:

svn diff --diff-cmd wm [optional-filename]

If you want to see what is actually happening here (i.e. what sort of parameters the svn diff passes to the nominated diff-cmd), you can just use svn diff --diff-cmd echo and see what it says:

[~/src/gosmore-dev]$ svn diff --diff-cmd echo
Index: gosmore.cpp
===================================================================
-u -L gosmore.cpp   (revision 13753) -L gosmore.cpp (working copy) .svn/text-base/gosmore.cpp.svn-base gosmore.cpp

Some quotes were removed above, but basically you can see that svn diff will pass

-u -L "<left-label>" -L "<right-label>" <left-file> <right-file> 

to your batch file. The batch file you have is used to turn these commands into the format that WinMerge understands.

More details and examples on how this all works are provided in the svn book.

To make your batch file the default for svn diff, you need to add the following line in the [helpers] section in your local subversion config file (~/.subversion/config in Linux, I'm not sure where the config file is located in Windows) (see this earlier SO question)

diff-cmd=wm.bat
9
votes

Check out this link:

http://blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/

Here is a copy for SOer's convienience:

Get this diffwrap.sh script and save it anywhere. I saved mine in my $HOME/bin directory. Make sure to make it executable! I’m showing it below:

#!/bin/sh
# Configure your favorite diff program here.
DIFF="/usr/bin/vimdiff" 
# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT="$6"
RIGHT="$7"
# Call the diff command (change the following line to make sense for
# your merge program).
"$DIFF" "$LEFT" "$RIGHT"

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

Then change your $HOME/.subversion/config file to point at that script:

[helpers]
diff-cmd = /home/matt/bin/diffwrap.sh

Then go diff a file!

4
votes

After creating a batch file that contains a call to your favorite merge program, you can configure Subversion to always use your batch file in Windows (without requiring the --diff-cmd argument on each use) by modifying the line

# diff-cmd = diff_program (diff, gdiff, etc.)

in the file C:\Documents and Settings\username\Application Data\Subversion\config. This line should be changed to point to your batch file. For example:

diff-cmd = c:\bin\wm.bat
4
votes

For Mac::

open this file : ~/.subversion/config

find and uncomment line containing : diff-cmd ( by removing # from start )

in front of diff-cmd, give the name of the diff tool, like in my case i was using araxis merge diff tool, so it looked like this :

diff-cmd=/Applications/Araxis Merge.app/Contents/Utilities/araxissvndiff

After this whenever you will run svn diff on terminal, if will show difference of the files in that tool

make sure there is no space before and after diff-cmd word.

3
votes

When using Cygwin and SVN 1.7 with WinMerge, use this batch file as the external diff tool. I had to adapt http://manual.winmerge.org/CommandLine.html to work with Cygwin paths.

In .subversion\config:

[helpers]
diff-cmd = C:\path\to\winmergesvndiff.bat

Contents of winmergesvndiff.bat

@echo off

set left=%6
set right=%7

REM Repeat these two lines for all drives
set left=%left:/cygdrive/c/=c:/%
set right=%right:/cygdrive/c/=c:/%

REM Path to WinMerge may vary
start "WinMerge" /B  "C:\program files (x86)\winmerge\WinMergeU.exe" /e /s /ub /dl %3 /dr %5 %left% %right%
3
votes

Meld works really great for me. After installing, I went to the Subversion config file, uncommented the diff-cmd line and set it to the path when meld.exe is. In my case:

[helpers]
### ...
### Set diff-cmd to the absolute path of your 'diff' program.
###   This will override the compile-time default, which is to use
###   Subversion's internal diff implementation.
diff-cmd = D:\SOFT\Meld\meld\meld.exe
2
votes

You need to convert the path to Windows style:

#!/bin/sh

LEFT="$6"
RIGHT="$7"

RRIGHT=`cygpath.exe -pw $RIGHT`
LLEFT=`cygpath.exe -pw $LEFT`

/cygdrive/c/Program\ Files\ \(x86\)/WinMerge/WinMergeU.exe /e /s /ub /dl %3 /dr %5 $LLEFT $RRIGHT
0
votes

Using Cygwin, Subversion (Cygwin's version) and WinDiff requires some care to deal with the latter's intolerance of forward slashes. I use the following Bash script, installed via svn's diff-cmd setting, to get the desired results with 'svn diff':

arg1=$(echo $6 | sed 's/\//\\/g' | sed 's/\\cygdrive\\c/c:/')
arg2=$(echo $7 | sed 's/\//\\/g' | sed 's/\\cygdrive\\c/c:/')
cmd /c windiff.exe $arg1 $arg2
0
votes

I had 3 issues with the simple .bat file, especially when the revision didn't match the one in the working directory:

  • svn may write the files to be compared to a temp directory - then delete them before WinMerge has a chance to look at them
  • svn may pick up the file from an .svn\pristine subdirectory, where its filename is a long string of hex digits
  • WinMerge bases its syntax highlighting on the file extensions and when svn uses a temp file, it has no extension

So I ended up wrapping a little PowerShell into the .bat file to work around these issues:

;@echo off
;set  leftdesc=%~3
;set rightdesc=%~5
;set  leftfile=%~6
;set rightfile=%~7
;Findstr -rbv ; %0 | powershell -c -
;goto:sCode

&{
  $leftExt, $rightExt = ($env:leftdesc, $env:rightdesc) -replace '.*([.]\w+).*','$1'
  if ($env:leftfile.EndsWith($leftExt)){
    $leftFile = $env:leftfile
  }else{
    $leftFile = Join-Path $env:temp ((Split-Path $env:leftfile -Leaf) + $leftExt)
    Copy-Item $env:leftfile $leftFile -Force
  }
  if ($env:rightfile.EndsWith($rightExt)){
    $rightFile = $env:rightfile
  }else{
    $rightFile = Join-Path $env:temp ((Split-Path $env:rightfile -Leaf) + $rightExt)
    Copy-Item $env:rightfile $rightFile -Force
  }
  $descriptions = '/dl "' + $env:leftdesc + '" /dr "' + $env:rightdesc + '"'
  $fileNames    = '"' + $leftFile + '" "' + $rightFile + '"'
  start 'C:\Program Files (x86)\WinMerge\WinMergeU.exe' ('/e /u ' +$descriptions + ' ' + $fileNames)
}

;:sCode
;goto :eof

Thanks to Walid Toumi for the wrapper.

0
votes

Something similar to the above answers worked for me, but, my particular setup required a bit of customization. Modifications for me were needed to (1) account for the "/tmp" directory in Cygwin, and (2) ensure the "/tmp" file stayed present (hence the "start" is gone from the launch of Meld).

The below .bat file worked for me with:

  • Cygwin (x64)
  • SVN (command line)
  • Meld
  • Windows 10

--

@echo off

set left=%6
set right=%7

REM Repeat these two lines for all drives
set left=%left:/cygdrive/d/=d:/%
set right=%right:/cygdrive/d/=d:/%
set left=%left:/tmp=c:/cygwin64/tmp%
set right=%right:/tmp=c:/cygwin64/tmp%

"C:\program files (x86)\meld\Meld.exe" %left% %right%