External diff

Subversion calls external diff programs with parameters suitable for the GNU diff utility, and it expects only that the external program will return with a successful error code. For most alternative diff programs, only the sixth and seventh arguments—the paths of the files that represent the left and right sides of the diff, respectively—are of interest. Note that Subversion runs the diff program once per modified file covered by the Subversion operation, so if your program runs in an asynchronous fashion (or is backgrounded), you might have several instances of it all running simultaneously. Finally, Subversion expects that your program will return an error code of 1 if your program detected differences, or 0 if it did not—any other error code is considered a fatal error.[51]

Examples 7-2 and 7-3 are templates for external diff tool wrappers in the Python and Windows batch scripting languages, respectively.

Example 7-2. diffwrap.py
#!/usr/bin/env python
import sys
import os

# Configure your favorite diff program here.
DIFF = "/usr/local/bin/my-diff-tool"

# Subversion provides the paths we need as the last two parameters.
LEFT  = sys.argv[-2]
RIGHT = sys.argv[-1]

# Call the diff command (change the following line to make sense for
# your diff program).
cmd = [DIFF, '--left', LEFT, '--right', RIGHT]
os.execv(cmd[0], cmd)

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.
Example 7-3. diffwrap.bat
@ECHO OFF

REM Configure your favorite diff program here.
SET DIFF="C:Program FilesFunky StuffMy Diff Tool.exe"

REM Subversion provides the paths we need as the last two parameters.
REM These are parameters 6 and 7 (unless you use svn diff -x, in
REM which case, all bets are off).
SET LEFT=%6
SET RIGHT=%7

REM Call the diff command (change the following line to make sense for
REM your diff program).
%DIFF% --left %LEFT% --right %RIGHT%

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


[51] The GNU diff manual page puts it this way: An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset