Patchwork D375: simplemerge: write merge result to the localctx, if passed

login
register
mail settings
Submitter phabricator
Date Aug. 14, 2017, 6:15 a.m.
Message ID <differential-rev-PHID-DREV-yqxqycfvfz64aawlvizy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22957/
State Superseded
Headers show

Comments

phabricator - Aug. 14, 2017, 6:15 a.m.
phillco created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D375

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




To: phillco, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 6, 2018, 11:03 p.m.
quark added a comment.


  https://bz.mercurial-scm.org/5743 bisects to this change.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D375

To: phillco, #hg-reviewers
Cc: quark, mercurial-devel

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -413,8 +413,8 @@ 
     """Performs the simplemerge algorithm.
 
     {local|base|other}ctx are optional. If passed, they (local/base/other) will
-    be read from. You should pass explicit labels in this mode since the default
-    is to use the file paths."""
+    be read from and the merge result written to (local). You should pass
+    explicit labels in this mode since the default is to use the file paths."""
     def readfile(filename):
         f = open(filename, "rb")
         text = f.read()
@@ -434,6 +434,17 @@ 
         return repo.wwritedata(ctx.path(),
                                _verifytext(ctx.data(), ctx.path(), ui, opts))
 
+    class ctxwriter(object):
+        def __init__(self, ctx):
+            self.ctx = ctx
+            self.text = ""
+
+        def write(self, text):
+            self.text += text
+
+        def close(self):
+            self.ctx.write(self.text, self.ctx.flags())
+
     mode = opts.get('mode','merge')
     if mode == 'union':
         name_a = None
@@ -460,12 +471,14 @@ 
     except error.Abort:
         return 1
 
-    localfile = os.path.realpath(localfile)
-    if not opts.get('print'):
+    if opts.get('print'):
+        out = ui.fout
+    elif localctx:
+        out = ctxwriter(localctx)
+    else:
+        localfile = os.path.realpath(localfile)
         opener = vfsmod.vfs(os.path.dirname(localfile))
         out = opener(os.path.basename(localfile), "w", atomictemp=True)
-    else:
-        out = ui.fout
 
     m3 = Merge3Text(basetext, localtext, othertext)
     extrakwargs = {