Patchwork D383: simplemerge: simplify code now that we always write to a context

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

Comments

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

REVISION SUMMARY
  There's no need for an `out` abstraction between files and contexts anymore.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -445,17 +445,6 @@ 
             text = _verifytext(ctx.data(), ctx.path(), ui, opts)
             return repo.wwritedata(ctx.path(), text)
 
-    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')
     name_a, name_b, name_base = None, None, None
     if mode != 'union':
@@ -470,11 +459,6 @@ 
     except error.Abort:
         return 1
 
-    if opts.get('print'):
-        out = ui.fout
-    else:
-        out = ctxwriter(localctx)
-
     m3 = Merge3Text(basetext, localtext, othertext)
     extrakwargs = {
             "localorother": opts.get("localorother", None),
@@ -488,12 +472,17 @@ 
         extrakwargs['base_marker'] = '|||||||'
         extrakwargs['name_base'] = name_base
         extrakwargs['minimize'] = False
+
+    mergedtext = ""
     for line in m3.merge_lines(name_a=name_a, name_b=name_b,
                                **pycompat.strkwargs(extrakwargs)):
-        out.write(line)
+        if opts.get('print'):
+            ui.fout.write(line)
+        else:
+            mergedtext += line
 
     if not opts.get('print'):
-        out.close()
+        localctx.write(mergedtext, localctx.flags())
 
     if m3.conflicts and not mode == 'union':
         return 1