Mercurial > hg-stable
changeset 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 | d9602f0df4f3 |
children | 86e4b86df932 |
files | contrib/simplemerge mercurial/filemerge.py mercurial/simplemerge.py |
diffstat | 3 files changed, 30 insertions(+), 24 deletions(-) [+] |
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))
--- a/mercurial/filemerge.py Thu Feb 10 15:48:01 2022 -0800 +++ b/mercurial/filemerge.py Fri Jan 14 08:17:13 2022 -0800 @@ -442,10 +442,13 @@ stringutil.binary(input.text()) for input in (local, base, other) ): return 1 # continue merging - r = simplemerge.simplemerge( - ui, local, base, other, quiet=True, mode=mode + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode ) - if not r: + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + local.fctx.write(merged_text, local.fctx.flags()) + if not conflicts: ui.debug(b" premerge successful\n") return 0 if premerge not in validkeep: @@ -489,8 +492,14 @@ _verifytext(other, ui) except error.Abort: return True, True, False - r = simplemerge.simplemerge(ui, local, base, other, mode=mode) - return True, r, False + else: + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode + ) + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + local.fctx.write(merged_text, local.fctx.flags()) + return True, conflicts, False @internaltool(
--- a/mercurial/simplemerge.py Thu Feb 10 15:48:01 2022 -0800 +++ b/mercurial/simplemerge.py Fri Jan 14 08:17:13 2022 -0800 @@ -532,11 +532,4 @@ lines, conflicts = render_minimized(m3, *labels) mergedtext = b''.join(lines) - if print_result: - ui.fout.write(mergedtext) - else: - # local.fctx.flags() already has the merged flags (done in - # mergestate.resolve()) - local.fctx.write(mergedtext, local.fctx.flags()) - - return conflicts + return mergedtext, conflicts