[PATCH 5 of 9] merge: introduce hasconflicts() on mergeresult object

Pulkit Goyal 7895pulkit at gmail.com
Thu Jul 30 06:53:27 UTC 2020


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1595580818 -19800
#      Fri Jul 24 14:23:38 2020 +0530
# Node ID b96b39636881b521a71cbdca9b202965f46be380
# Parent  94e7528a24c54cdd8da2e1470a101d55ac87a1dd
# EXP-Topic merge-refactor
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 _, (m, _, _) 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




More information about the Mercurial-devel mailing list