merge: introduce hasconflicts() on mergeresult object
This and upcoming patches will improve the mergeresult object making it more
powerful and provide clean APIs for various things. Doing this will clean up the
core merge code which is present in `update()` a bit.
Differential Revision: https://phab.mercurial-scm.org/D8816
--- a/mercurial/merge.py Tue Jul 14 16:40:28 2020 +0530
+++ b/mercurial/merge.py Sun Aug 02 10:12:21 2020 -0700
@@ -581,6 +581,21 @@
def setactions(self, actions):
self._actions = actions
+ def hasconflicts(self):
+ """ tells whether this merge resulted in some actions which can
+ result in conflicts or not """
+ for _f, (m, _unused, _unused) in pycompat.iteritems(self._actions):
+ if m not in (
+ mergestatemod.ACTION_GET,
+ mergestatemod.ACTION_KEEP,
+ mergestatemod.ACTION_EXEC,
+ mergestatemod.ACTION_REMOVE,
+ mergestatemod.ACTION_PATH_CONFLICT_RESOLVE,
+ ):
+ return True
+
+ return False
+
def manifestmerge(
repo,
@@ -1809,17 +1824,10 @@
actionbyfile = mresult.actions
if updatecheck == UPDATECHECK_NO_CONFLICT:
- for f, (m, args, msg) in pycompat.iteritems(actionbyfile):
- if m not in (
- mergestatemod.ACTION_GET,
- mergestatemod.ACTION_KEEP,
- mergestatemod.ACTION_EXEC,
- mergestatemod.ACTION_REMOVE,
- mergestatemod.ACTION_PATH_CONFLICT_RESOLVE,
- ):
- msg = _(b"conflicting changes")
- hint = _(b"commit or update --clean to discard changes")
- raise error.Abort(msg, hint=hint)
+ if mresult.hasconflicts():
+ msg = _(b"conflicting changes")
+ hint = _(b"commit or update --clean to discard changes")
+ raise error.Abort(msg, hint=hint)
# Prompt and create actions. Most of this is in the resolve phase
# already, but we can't handle .hgsubstate in filemerge or