mercurial/merge.py
changeset 6003 7855b88ba838
parent 5857 c704b03884ef
child 6211 f89fd07fc51d
--- a/mercurial/merge.py	Sun Feb 03 19:29:05 2008 -0600
+++ b/mercurial/merge.py	Sun Feb 03 19:29:05 2008 -0600
@@ -7,62 +7,7 @@
 
 from node import *
 from i18n import _
-import errno, util, os, tempfile, context, heapq
-
-def filemerge(repo, fw, fd, fo, wctx, mctx):
-    """perform a 3-way merge in the working directory
-
-    fw = original filename in the working directory
-    fd = destination filename in the working directory
-    fo = filename in other parent
-    wctx, mctx = working and merge changecontexts
-    """
-
-    def temp(prefix, ctx):
-        pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
-        (fd, name) = tempfile.mkstemp(prefix=pre)
-        data = repo.wwritedata(ctx.path(), ctx.data())
-        f = os.fdopen(fd, "wb")
-        f.write(data)
-        f.close()
-        return name
-
-    fcm = wctx.filectx(fw)
-    fcmdata = wctx.filectx(fd).data()
-    fco = mctx.filectx(fo)
-
-    if not fco.cmp(fcmdata): # files identical?
-        return None
-
-    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)
-
-    if fw != fo:
-        repo.ui.status(_("merging %s and %s\n") % (fw, fo))
-    else:
-        repo.ui.status(_("merging %s\n") % fw)
-
-    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)
-
-    os.unlink(b)
-    os.unlink(c)
-    return r
+import errno, util, os, heapq, filemerge
 
 def checkunknown(wctx, mctx):
     "check for collisions between unknown files and files in mctx"
@@ -514,7 +459,7 @@
             removed += 1
         elif m == "m": # merge
             f2, fd, flags, move = a[2:]
-            r = filemerge(repo, f, fd, f2, wctx, mctx)
+            r = filemerge.filemerge(repo, f, fd, f2, wctx, mctx)
             if r > 0:
                 unresolved += 1
             else: