diff mercurial/commands.py @ 12788:de793925862e

merge: implement --tool arguments using new ui.forcemerge configurable ui.forcemerge is set before calling into merge or resolve commands, then unset to prevent ui pollution for further operations. ui.forcemerge takes precedence over HGMERGE, but mimics HGMERGE behavior if the given --tool is not found by the merge-tools machinery. This makes it possible to do: hg resolve --tool="python mymerge.py" FILE With this approach, HGMERGE and ui.merge are not harmed by --tool
author Steve Borho <steve@borho.org>
date Tue, 19 Oct 2010 22:33:52 -0500
parents 5eed9ceebd64
children a6a0698960cc
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Oct 20 20:19:34 2010 +0200
+++ b/mercurial/commands.py	Tue Oct 19 22:33:52 2010 -0500
@@ -2586,12 +2586,6 @@
     if not node:
         node = opts.get('rev')
 
-    t = opts.get('tool')
-    if t:
-        if 'HGMERGE' in os.environ:
-            os.environ['HGMERGE'] = ''
-        ui.setconfig('ui', 'merge', t)
-
     if not node:
         branch = repo.changectx(None).branch()
         bheads = repo.branchheads(branch)
@@ -2632,7 +2626,12 @@
         displayer.close()
         return 0
 
-    return hg.merge(repo, node, force=opts.get('force'))
+    try:
+        # ui.forcemerge is an internal variable, do not document
+        ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
+        return hg.merge(repo, node, force=opts.get('force'))
+    finally:
+        ui.setconfig('ui', 'forcemerge', '')
 
 def outgoing(ui, repo, dest=None, **opts):
     """show changesets not found in the destination
@@ -2979,12 +2978,6 @@
         raise util.Abort(_('no files or directories specified; '
                            'use --all to remerge all files'))
 
-    t = opts.get('tool')
-    if t:
-        if 'HGMERGE' in os.environ:
-            os.environ['HGMERGE'] = ''
-        ui.setconfig('ui', 'merge', t)
-
     ms = mergemod.mergestate(repo)
     m = cmdutil.match(repo, pats, opts)
     ret = 0
@@ -3010,9 +3003,13 @@
                 a = repo.wjoin(f)
                 util.copyfile(a, a + ".resolve")
 
-                # resolve file
-                if ms.resolve(f, wctx, mctx):
-                    ret = 1
+                try:
+                    # resolve file
+                    ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
+                    if ms.resolve(f, wctx, mctx):
+                        ret = 1
+                finally:
+                    ui.setconfig('ui', 'forcemerge', '')
 
                 # replace filemerge's .orig file with our resolve file
                 util.rename(a + ".resolve", a + ".orig")