[PATCH 5 of 5] simplemerge: write merge result to the localctx, if passed
Phil Cohen
phillco at fb.com
Mon Jul 3 00:40:21 EDT 2017
# HG changeset patch
# User Phil Cohen <phillco at fb.com>
# Date 143 28800
# Wed Dec 31 16:02:23 1969 -0800
# Node ID 059e7871014a98dacc341e68e12356c40280cb58
# Parent f78fd50a5595fc0ffc9b261a9ee1fad3f97aa7d6
simplemerge: write merge result to the localctx, if passed
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -412,8 +412,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()
@@ -433,6 +433,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
@@ -459,12 +470,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 = {
More information about the Mercurial-devel
mailing list