Patchwork D378: contrib: make simplemerge script pass context-like objects

login
register
mail settings
Submitter phabricator
Date Aug. 25, 2017, 4:32 a.m.
Message ID <de58d78a480c79481e464be68e5ae297@localhost.localdomain>
Download mbox | patch
Permalink /patch/23320/
State Not Applicable
Headers show

Comments

phabricator - Aug. 25, 2017, 4:32 a.m.
phillco updated this revision to Diff 1277.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D378?vs=1038&id=1277

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

AFFECTED FILES
  contrib/simplemerge

CHANGE DETAILS




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

Patch

diff --git a/contrib/simplemerge b/contrib/simplemerge
--- a/contrib/simplemerge
+++ b/contrib/simplemerge
@@ -49,6 +49,26 @@ 
     for first, second in out_opts:
         sys.stdout.write(' %-*s  %s\n' % (opts_len, first, second))
 
+class filebackedctx(object):
+    """simplemerge requires context-like objects"""
+    def __init__(self, path):
+        self._path = path
+
+    def decodeddata(self):
+        with open(self._path, "rb") as f:
+            return f.read()
+
+    def flags(self):
+        return ''
+
+    def path(self):
+        return self._path
+
+    def write(self, data, flags):
+        assert not flags
+        with open(self._path, "w") as f:
+            f.write(data)
+
 try:
     for fp in (sys.stdin, sys.stdout, sys.stderr):
         util.setbinary(fp)
@@ -63,7 +83,16 @@ 
         sys.exit(0)
     if len(args) != 3:
             raise ParseError(_('wrong number of arguments'))
-    sys.exit(simplemerge.simplemerge(uimod.ui.load(), *args, **opts))
+    local, base, other = args
+    sys.exit(simplemerge.simplemerge(uimod.ui.load(),
+                                     local,
+                                     base,
+                                     other,
+                                     filebackedctx(local),
+                                     filebackedctx(base),
+                                     filebackedctx(other),
+                                     filtereddata=True,
+                                     **opts))
 except ParseError as e:
     sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
     showhelp()