diff mercurial/merge.py @ 45530:6877b0ee5f9d

mergestate: introduce a new ACTION_KEEP_NEW `ACTION_KEEP` is overloaded and it's hard to figure out how we end up with this KEEP, what was the state of things. In a previous patch, we introduced `ACTION_KEEP_ABSENT` which represents files which are kept absent in the working directory. There is another special case where we keep the file when it's not present on both ancestor and remote side. We introduce a dedicated action for that. The goal is to use these information to make bid merge smarter. Differential Revision: https://phab.mercurial-scm.org/D9002
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 09 Sep 2020 16:49:19 +0530
parents 32ce4cbaec4b
children 590a840fa367
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Sep 21 10:23:25 2020 -0400
+++ b/mercurial/merge.py	Wed Sep 09 16:49:19 2020 +0530
@@ -552,6 +552,7 @@
     NO_OP_ACTIONS = (
         mergestatemod.ACTION_KEEP,
         mergestatemod.ACTION_KEEP_ABSENT,
+        mergestatemod.ACTION_KEEP_NEW,
     )
 
     def __init__(self):
@@ -921,7 +922,7 @@
             else:  # file not in ancestor, not in remote
                 mresult.addfile(
                     f,
-                    mergestatemod.ACTION_KEEP,
+                    mergestatemod.ACTION_KEEP_NEW,
                     None,
                     b'ancestor missing, remote missing',
                 )
@@ -1191,6 +1192,11 @@
                 repo.ui.note(_(b" %s: picking 'keep absent' action\n") % f)
                 mresult.addfile(f, *bids[mergestatemod.ACTION_KEEP_ABSENT][0])
                 continue
+            # If keep new is an option, let's just do that
+            if mergestatemod.ACTION_KEEP_NEW in bids:
+                repo.ui.note(_(b" %s: picking 'keep new' action\n") % f)
+                mresult.addfile(f, *bids[mergestatemod.ACTION_KEEP_NEW][0])
+                continue
             # If there are gets and they all agree [how could they not?], do it.
             if mergestatemod.ACTION_GET in bids:
                 ga0 = bids[mergestatemod.ACTION_GET][0]
@@ -1496,16 +1502,10 @@
         progress.increment(item=f)
 
     # keep (noop, just log it)
-    for f, args, msg in mresult.getactions(
-        (mergestatemod.ACTION_KEEP,), sort=True
-    ):
-        repo.ui.debug(b" %s: %s -> k\n" % (f, msg))
-        # no progress
-    for f, args, msg in mresult.getactions(
-        (mergestatemod.ACTION_KEEP_ABSENT,), sort=True
-    ):
-        repo.ui.debug(b" %s: %s -> ka\n" % (f, msg))
-        # no progress
+    for a in mergeresult.NO_OP_ACTIONS:
+        for f, args, msg in mresult.getactions((a,), sort=True):
+            repo.ui.debug(b" %s: %s -> %s\n" % (f, msg, a))
+            # no progress
 
     # directory rename, move local
     for f, args, msg in mresult.getactions(