Mercurial > hg
diff contrib/simplemerge @ 34051:d2fc88426d21
context: add arbitraryfilectx, which can represent files outside the workdir
Move it from contrib/simplemerge so it can be re-used in the future.
Differential Revision: https://phab.mercurial-scm.org/D604
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Fri, 01 Sep 2017 11:52:20 -0700 |
parents | b4226ad98366 |
children | a8a902d7176e |
line wrap: on
line diff
--- a/contrib/simplemerge Fri Sep 01 10:35:43 2017 -0700 +++ b/contrib/simplemerge Fri Sep 01 11:52:20 2017 -0700 @@ -9,6 +9,7 @@ from mercurial.i18n import _ from mercurial import ( + context, error, fancyopts, simplemerge, @@ -49,26 +50,6 @@ 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) @@ -85,9 +66,9 @@ raise ParseError(_('wrong number of arguments')) local, base, other = args sys.exit(simplemerge.simplemerge(uimod.ui.load(), - filebackedctx(local), - filebackedctx(base), - filebackedctx(other), + context.arbitraryfilectx(local), + context.arbitraryfilectx(base), + context.arbitraryfilectx(other), **opts)) except ParseError as e: sys.stdout.write("%s: %s\n" % (sys.argv[0], e))