Mercurial > hg-stable
diff contrib/simplemerge @ 48758:6ae3c97a0919
simplemerge: move printing of merge result to extension
The `mercurial.simplemerge` module still has some command-lines
processing that doesn't belong in such a low-level module. This patch
moves the handling of `hg simplemerge --print` to the extension by
having `mercurial.simplemerge.simplemerge()` return the merged text.
Differential Revision: https://phab.mercurial-scm.org/D12148
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 14 Jan 2022 08:17:13 -0800 |
parents | 109fec7bf7de |
children | 7dad4665d223 |
line wrap: on
line diff
--- a/contrib/simplemerge Thu Feb 10 15:48:01 2022 -0800 +++ b/contrib/simplemerge Fri Jan 14 08:17:13 2022 -0800 @@ -15,6 +15,7 @@ fancyopts, simplemerge, ui as uimod, + util, ) from mercurial.utils import procutil, stringutil @@ -116,18 +117,21 @@ _verifytext(base_input, ui, quiet=quiet, allow_binary=allow_binary) _verifytext(other_input, ui, quiet=quiet, allow_binary=allow_binary) - sys.exit( - simplemerge.simplemerge( - ui, - local_input, - base_input, - other_input, - mode, - quiet=True, - allow_binary=allow_binary, - print_result=opts.get(b'print'), - ) + merged_text, conflicts = simplemerge.simplemerge( + ui, + local_input, + base_input, + other_input, + mode, + quiet=True, + allow_binary=allow_binary, + print_result=opts.get(b'print'), ) + if opts.get(b'print'): + ui.fout.write(merged_text) + else: + util.writefile(local, merged_text) + sys.exit(1 if conflicts else 0) except ParseError as e: e = stringutil.forcebytestr(e) procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))