# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-08-02 17:12:21 # Node ID 0c849f0166c265c68d8608442e3b206b54de83fd # Parent c515c54f6530f04923827b575b3d9493f271e3c6 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 diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -581,6 +581,21 @@ class mergeresult(object): 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 @@ def update( 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