Patchwork [2,of,3] extdiff: allow a preconfigured merge-tool to be invoked

login
register
mail settings
Submitter Matt Harbison
Date Nov. 2, 2014, 8:58 p.m.
Message ID <c83902f33e07c7546fd2.1414961902@Envy>
Download mbox | patch
Permalink /patch/6534/
State Accepted
Headers show

Comments

Matt Harbison - Nov. 2, 2014, 8:58 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1414805695 14400
#      Fri Oct 31 21:34:55 2014 -0400
# Branch stable
# Node ID c83902f33e07c7546fd2c0bf0184456265f08043
# Parent  f72827d6b96cb953432fff89a0bd3b13a142e826
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 =

Patch

diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -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 \
diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t
--- a/tests/test-extdiff.t
+++ b/tests/test-extdiff.t
@@ -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 /tmp/extdiff.* (glob)
+  ** custom diff **
+  cleaning up temp directory
+  [1]
+
   $ cd ..
 
 #endif
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -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