D12148: simplemerge: move printing of merge result to extension
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Tue Feb 8 21:28:18 UTC 2022
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
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.
I had to signal in some way that no merge was done because an input
was binary. I decided to use a resulting text value of `None` for
that.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12148
AFFECTED FILES
contrib/simplemerge
mercurial/filemerge.py
mercurial/simplemerge.py
CHANGE DETAILS
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -522,11 +522,4 @@
lines, conflicts = render_minimized(m3, *labels)
mergedtext = b''.join(lines)
- if opts.get('print'):
- 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
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -434,12 +434,18 @@
base.verifytext(ui, quiet=True)
other.verifytext(ui, quiet=True)
except error.Abort:
- r = True
+ return 1
else:
- r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
- if not r:
- ui.debug(b" premerge successful\n")
- return 0
+ merged_text, conflicts = simplemerge.simplemerge(
+ ui, local, base, other, mode=mode
+ )
+ # fcd.flags() already has the merged flags (done in
+ # mergestate.resolve())
+ if merged_text is not None:
+ local.fctx.write(merged_text, local.fctx.flags())
+ if not conflicts:
+ ui.debug(b" premerge successful\n")
+ return 0
if premerge not in validkeep:
# restore from backup and try again
_restorebackup(local.fctx, backup)
@@ -480,10 +486,16 @@
base.verifytext(ui)
other.verifytext(ui)
except error.Abort:
- r = True
+ conflicts = True
else:
- r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
- return True, r, False
+ merged_text, conflicts = simplemerge.simplemerge(
+ ui, local, base, other, mode=mode
+ )
+ # fcd.flags() already has the merged flags (done in
+ # mergestate.resolve())
+ if merged_text is not None:
+ local.fctx.write(merged_text, local.fctx.flags())
+ return True, conflicts, False
@internaltool(
diff --git a/contrib/simplemerge b/contrib/simplemerge
--- a/contrib/simplemerge
+++ b/contrib/simplemerge
@@ -106,11 +106,16 @@
except error.Abort:
sys.exit(1)
- sys.exit(
- simplemerge.simplemerge(
- ui, local_input, base_input, other_input, **opts
- )
+ merged_text, conflicts = simplemerge.simplemerge(
+ ui, local_input, base_input, other_input, **opts
)
+ if merged_text is not None:
+ if opts['print']:
+ ui.fout.write(merged_text)
+ else:
+ with open(local, 'wb') as f:
+ f.write(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))
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list