Patchwork D8816: merge: introduce hasconflicts() on mergeresult object

login
register
mail settings
Submitter phabricator
Date July 25, 2020, 9:59 a.m.
Message ID <differential-rev-PHID-DREV-tud54n5ceon6yfvchhip-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46887/
State Superseded
Headers show

Comments

phabricator - July 25, 2020, 9:59 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8816

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -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 _, (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 @@ 
         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