extdiff: allow a preconfigured merge-tool to be invoked
There are three ways to configure an extdiff tool:
1) cmd.tool = (/path/to/exe optional)
2) tool = (path/to/exe optional)
3) tool = sometool someargs
Previously, if no executable is specified in the first two forms, the named tool
must be in $PATH, or the invocation fails. Since the [merge-tools] section
already has the path to the diff executable, and/or the registry keys to find
the executable on Windows, reuse that configuration for forms 1 and 2 instead of
failing. We already fallback to [diff-tools] and then [merge-tools] for program
arguments if they aren't specified in the [extdiff] section.
Since this additional lookup only occurs if an executable is not on the $PATH
for the named tool, this is backwards compatible. For now, we assume the user
knows what he is doing if a path is provided.
This change allows a configuration file like this (assuming beyondcompare3 is
configured in merge-tools), instead of hardcoding system specific a path:
[extdiff]
beyondcompare3 =
--- a/hgext/extdiff.py Mon Nov 03 16:30:21 2014 -0600
+++ b/hgext/extdiff.py Fri Oct 31 21:34:55 2014 -0400
@@ -26,7 +26,9 @@
# add new command called vdiff, runs kdiff3
vdiff = kdiff3
- # add new command called meld, runs meld (no need to name twice)
+ # add new command called meld, runs meld (no need to name twice). If
+ # the meld executable is not available, the meld tool in [merge-tools]
+ # will be used, if available
meld =
# add new command called vimdiff, runs gvimdiff with DirDiff plugin
@@ -63,7 +65,7 @@
from mercurial.i18n import _
from mercurial.node import short, nullid
-from mercurial import cmdutil, scmutil, util, commands, encoding
+from mercurial import cmdutil, scmutil, util, commands, encoding, filemerge
import os, shlex, shutil, tempfile, re
cmdtable = {}
@@ -279,7 +281,9 @@
if cmd.startswith('cmd.'):
cmd = cmd[4:]
if not path:
- path = cmd
+ path = util.findexe(cmd)
+ if path is None:
+ path = filemerge.findexternaltool(ui, cmd) or cmd
diffopts = ui.config('extdiff', 'opts.' + cmd, '')
diffopts = diffopts and [diffopts] or []
elif cmd.startswith('opts.'):
@@ -290,7 +294,9 @@
diffopts = shlex.split(path)
path = diffopts.pop(0)
else:
- path, diffopts = cmd, []
+ path, diffopts = util.findexe(cmd), []
+ if path is None:
+ path = filemerge.findexternaltool(ui, cmd) or cmd
# look for diff arguments in [diff-tools] then [merge-tools]
if diffopts == []:
args = ui.config('diff-tools', cmd+'.diffargs') or \
--- a/tests/test-extdiff.t Mon Nov 03 16:30:21 2014 -0600
+++ b/tests/test-extdiff.t Fri Oct 31 21:34:55 2014 -0400
@@ -178,6 +178,26 @@
*/extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob)
[1]
+Fallback to merge-tools.tool.executable|regkey
+ $ mkdir dir
+ $ cat > 'dir/tool.sh' << EOF
+ > #!/bin/sh
+ > echo "** custom diff **"
+ > EOF
+ $ chmod +x dir/tool.sh
+ $ tool=`pwd`/dir/tool.sh
+ $ hg --debug tl --config extdiff.tl= --config merge-tools.tl.executable=$tool
+ making snapshot of 2 files from rev * (glob)
+ a
+ b
+ making snapshot of 2 files from working directory
+ a
+ b
+ running "'$TESTTMP/a/dir/tool.sh' 'a.*' 'a'" in */extdiff.* (glob)
+ ** custom diff **
+ cleaning up temp directory
+ [1]
+
$ cd ..
#endif
--- a/tests/test-extension.t Mon Nov 03 16:30:21 2014 -0600
+++ b/tests/test-extension.t Fri Oct 31 21:34:55 2014 -0400
@@ -427,7 +427,9 @@
# add new command called vdiff, runs kdiff3
vdiff = kdiff3
- # add new command called meld, runs meld (no need to name twice)
+ # add new command called meld, runs meld (no need to name twice). If
+ # the meld executable is not available, the meld tool in [merge-tools]
+ # will be used, if available
meld =
# add new command called vimdiff, runs gvimdiff with DirDiff plugin