[PATCH 2 of 4] hgmerge: integrate new merge subsystem

Steve Borho steve at borho.org
Mon Jan 7 15:20:35 CST 2008


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1199739440 21600
# Node ID 6723773fcf55d2da2ecb1becf8ccdcb8e788ed6c
# Parent  1dabe5c4867c4f1d855494ecd0f76d6436882c6e
hgmerge: integrate new merge subsystem

Change merge.py use hgmerge as default fallback.
Update debuginstall command to list detected plug-ins

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -810,37 +810,43 @@ def debuginstall(ui):
 
     # merge helper
     ui.status(_("Checking merge helper...\n"))
-    cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge")
-           or "hgmerge")
-    cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
-    if not cmdpath:
-        if cmd == 'hgmerge':
-            ui.write(_(" No merge helper set and can't find default"
-                       " hgmerge script in PATH\n"))
-            ui.write(_(" (specify a merge helper in your .hgrc file)\n"))
+    cmd = os.environ.get("HGMERGE") or ui.config("ui", "merge")
+    if not cmd:
+        # internal hgmerge wrapper
+        import hgmerge
+        tools = hgmerge.query_plugins(ui, True)
+        if tools:
+            names = [tool.name for tool in tools]
+            ui.status(_(" Found merge tool(s): %s\n" % ', '.join(names)))
         else:
-            ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
-            ui.write(_(" (specify a merge helper in your .hgrc file)\n"))
+            ui.write(_(" Can't find any merge tools\n"))
+            ui.write(_(" (specify a merge tool in your .hgrc file)\n"))
             problems += 1
     else:
-        # actually attempt a patch here
-        fa = writetemp("1\n2\n3\n4\n")
-        fl = writetemp("1\n2\n3\ninsert\n4\n")
-        fr = writetemp("begin\n1\n2\n3\n4\n")
-        r = util.system('%s "%s" "%s" "%s"' % (cmd, fl, fa, fr))
-        if r:
-            ui.write(_(" Got unexpected merge error %d!\n") % r)
+        cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0])
+        if not cmdpath:
+            ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd)
+            ui.write(_(" (specify merge helper path in your .hgrc file)\n"))
             problems += 1
-        m = file(fl).read()
-        if m != "begin\n1\n2\n3\ninsert\n4\n":
-            ui.write(_(" Got unexpected merge results!\n"))
-            ui.write(_(" (your merge helper may have the"
-                       " wrong argument order)\n"))
-            ui.write(_(" Result: %r\n") % m)
-            problems += 1
-        os.unlink(fa)
-        os.unlink(fl)
-        os.unlink(fr)
+        else:
+            # actually attempt a patch here
+            fa = writetemp("1\n2\n3\n4\n")
+            fl = writetemp("1\n2\n3\ninsert\n4\n")
+            fr = writetemp("begin\n1\n2\n3\n4\n")
+            r = util.system('%s "%s" "%s" "%s"' % (cmd, fl, fa, fr))
+            if r:
+                ui.write(_(" Got unexpected merge error %d!\n") % r)
+                problems += 1
+            m = file(fl).read()
+            if m != "begin\n1\n2\n3\ninsert\n4\n":
+                ui.write(_(" Got unexpected merge results!\n"))
+                ui.write(_(" (your merge helper may have the"
+                           " wrong argument order)\n"))
+                ui.write(_(" Result: %r\n") % m)
+                problems += 1
+            os.unlink(fa)
+            os.unlink(fl)
+            os.unlink(fr)
 
     # editor
     ui.status(_("Checking commit editor...\n"))
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -8,6 +8,8 @@ from node import *
 from node import *
 from i18n import _
 import errno, util, os, tempfile, context, heapq
+
+from mercurial import hgmerge
 
 def filemerge(repo, fw, fd, fo, wctx, mctx):
     """perform a 3-way merge in the working directory
@@ -37,9 +39,15 @@ def filemerge(repo, fw, fd, fo, wctx, mc
     fca = fcm.ancestor(fco)
     if not fca:
         fca = repo.filectx(fw, fileid=nullrev)
-    a = repo.wjoin(fd)
-    b = temp("base", fca)
-    c = temp("other", fco)
+    a = hgmerge.filedesc(repo.wjoin(fd), fcm.islink())
+    b = hgmerge.filedesc(temp("base", fca), fca.islink())
+    c = hgmerge.filedesc(temp("other", fco), fco.islink())
+    mergeenv={'HG_FILE': fd,
+             'HG_MY_NODE': str(wctx.parents()[0]),
+             'HG_OTHER_NODE': str(mctx),
+             'HG_MY_ISLINK': a.islink,
+             'HG_OTHER_ISLINK': c.islink,
+             'HG_BASE_ISLINK': b.islink,}
 
     if fw != fo:
         repo.ui.status(_("merging %s and %s\n") % (fw, fo))
@@ -48,20 +56,17 @@ def filemerge(repo, fw, fd, fo, wctx, mc
 
     repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca))
 
-    cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
-           or "hgmerge")
-    r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
-                    environ={'HG_FILE': fd,
-                             'HG_MY_NODE': str(wctx.parents()[0]),
-                             'HG_OTHER_NODE': str(mctx),
-                             'HG_MY_ISLINK': fcm.islink(),
-                             'HG_OTHER_ISLINK': fco.islink(),
-                             'HG_BASE_ISLINK': fca.islink(),})
-    if r:
-        repo.ui.warn(_("merging %s failed!\n") % fd)
+    cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge"))
+    if cmd:
+        r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
+                        environ=mergeenv)
+        if r:
+            repo.ui.warn(_("merging %s failed!\n") % fd)
+    else:
+        r = hgmerge.merge(repo, a, b, c)
 
-    os.unlink(b)
-    os.unlink(c)
+    os.unlink(b.name)
+    os.unlink(c.name)
     return r
 
 def checkunknown(wctx, mctx):


More information about the Mercurial-devel mailing list