changeset 45275:8e8d513941b4

merge: introduce 'commitinfo' in mergeresult commitinfo will be used to pass information which is required on commit phase from the merge phase. One common example is, merge chooses filenode from second parent and we need to tell commit to choose that. Right now this one and related cases are not very neatly implement and there is no clear line on how to pass on such information. Upcoming patches will try to work on in this area and make things easier. Differential Revision: https://phab.mercurial-scm.org/D8742
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 14 Jul 2020 16:21:08 +0530
parents 0e18861f96ab
children cb6a72dc0511
files hgext/convert/hg.py mercurial/merge.py
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Thu Jul 23 18:03:14 2020 +0530
+++ b/hgext/convert/hg.py	Tue Jul 14 16:21:08 2020 +0530
@@ -217,6 +217,7 @@
         """
         anc = [p1ctx.ancestor(p2ctx)]
         # Calculate what files are coming from p2
+        # TODO: mresult.commitinfo might be able to get that info
         mresult = mergemod.calculateupdates(
             self.repo,
             p1ctx,
--- a/mercurial/merge.py	Thu Jul 23 18:03:14 2020 +0530
+++ b/mercurial/merge.py	Tue Jul 14 16:21:08 2020 +0530
@@ -546,18 +546,21 @@
     It has information about what actions need to be performed on dirstate
     mapping of divergent renames and other such cases. '''
 
-    def __init__(self, actions, diverge, renamedelete):
+    def __init__(self, actions, diverge, renamedelete, commitinfo):
         """
         actions: dict of filename as keys and action related info as values
         diverge: mapping of source name -> list of dest name for
                  divergent renames
         renamedelete: mapping of source name -> list of destinations for files
                       deleted on one side and renamed on other.
+        commitinfo: dict containing data which should be used on commit
+                    contains a filename -> info mapping
         """
 
         self._actions = actions
         self._diverge = diverge
         self._renamedelete = renamedelete
+        self._commitinfo = commitinfo
 
     @property
     def actions(self):
@@ -571,6 +574,10 @@
     def renamedelete(self):
         return self._renamedelete
 
+    @property
+    def commitinfo(self):
+        return self._commitinfo
+
     def setactions(self, actions):
         self._actions = actions
 
@@ -608,6 +615,10 @@
     branch_copies1 = copies.branch_copies()
     branch_copies2 = copies.branch_copies()
     diverge = {}
+    # information from merge which is needed at commit time
+    # for example choosing filelog of which parent to commit
+    # TODO: use specific constants in future for this mapping
+    commitinfo = {}
     if followcopies:
         branch_copies1, branch_copies2, diverge = copies.mergecopies(
             repo, wctx, p2, pa
@@ -701,6 +712,8 @@
                             (fl2, False),
                             b'remote is newer',
                         )
+                        if branchmerge:
+                            commitinfo[f] = b'other'
                 elif nol and n2 == a:  # remote only changed 'x'
                     actions[f] = (
                         mergestatemod.ACTION_EXEC,
@@ -715,6 +728,8 @@
                         (fl1, False),
                         b'remote is newer',
                     )
+                    if branchmerge:
+                        commitinfo[f] = b'other'
                 else:  # both changed something
                     actions[f] = (
                         mergestatemod.ACTION_MERGE,
@@ -875,7 +890,7 @@
     renamedelete = branch_copies1.renamedelete
     renamedelete.update(branch_copies2.renamedelete)
 
-    return mergeresult(actions, diverge, renamedelete)
+    return mergeresult(actions, diverge, renamedelete, commitinfo)
 
 
 def _resolvetrivial(repo, wctx, mctx, ancestor, actions):
@@ -1034,7 +1049,8 @@
             actions[f] = l[0]
             continue
         repo.ui.note(_(b'end of auction\n\n'))
-        mresult = mergeresult(actions, diverge, renamedelete)
+        # TODO: think about commitinfo when bid merge is used
+        mresult = mergeresult(actions, diverge, renamedelete, {})
 
     if wctx.rev() is None:
         fractions = _forgetremoved(wctx, mctx, branchmerge)