Article Index

Using WinDiff with SubVersion

This is a tip for anyone using the SubVersion command-line client (svn.exe) that can't mentally process unix-style diff output.

By default, running the svn diff command on a modified file in your working directly will dump diff output to the console:

C:\work\ProfileView>svn diff
Index: ControlBuilder.cs
===================================================================
--- ControlBuilder.cs   (revision 25)
+++ ControlBuilder.cs   (working copy)
@@ -59,10 +59,11 @@
             if (validationType != ValidationDataType.String)
             {
                 validator = new CompareValidator();
-                validator.ID = "val_" + property.Name;
+                validator.ID = "v" + property.Name;
                 validator.Operator = ValidationCompareOperator.DataTypeCheck;
                 validator.Type = validationType;
                 validator.ValidationGroup = DEFAULT_VALIDATION_GROUP;
+                validator.SkinID = "validators";
                 validator.ErrorMessage = DEFAULT_VALIDATION_ERROR_MESSAGE;
                 validator.Display = ValidatorDisplay.Dynamic;
             }

In this simple example, you can probably figure out what changed. But if the modifications were more extensive, the output would be harder to interpret.

Enter WinDiff. WinDiff is a graphical utility for visually comparing 2 files or the contents of 2 folders. There are many other similar tools available - I choose WinDiff because its free, and its already on my system. It comes with Visual Studio .NET (if you install the VC++ Tools); or if you don't own VS.NET, you can get it with the Windows Support Tools.

The SubVersion client allows you to specify a 3rd party diff tool using the diff-cmd argument. However, the argument list it passes to the tool does not match the input arguments that windiff.exe is expecting. The solution is to create an intermediate batch file that translates the arguments. I created svnwindiff.bat in my SubVersion install folder (c:\apps\subversion). It contains a single command:
"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\windiff.exe" %6 %7

I then specify this batch file as my external diff tool:
C:\work\ProfileView>svn diff --diff-cmd c:\apps\subversion\svnwindiff.bat

Which will open the following window: Changes viewed in WinDiff

Finally, to save yourself some typing, you can set WinDiff as your default diff tool by editing your SubVersion config file located at:
C:\Documents and Settings\username\Application Data\Subversion\config

Find the commented (#) line for diff-cmd, uncomment it and set the path, so it looks something like this:
diff-cmd = c:\apps\subversion\svnwindiff.bat

Now, simply typing svn diff at a command-line will automatically launch WinDiff to visually display the differences.

Update: I've been taken to task for mentioning an ancient diff tool like WinDiff. While I stand by my initial reason for WinDiff ("its already on my system"), I figure it's in your best interest that I mention some more modern alternatives. A few free ones: KDiff3, WinMerge, and ExamDiff. Scott seems to like the $30 Beyond Compare (although it is conspicuosly missing from his Ultimate Tools List).