Patchwork [2,of,9] merge: introduce 'commitinfo' in mergeresult

login
register
mail settings
Submitter Pulkit Goyal
Date July 30, 2020, 6:53 a.m.
Message ID <095b5d6b721c7068dd2e.1596092004@workspace>
Download mbox | patch
Permalink /patch/46940/
State New
Headers show

Comments

Pulkit Goyal - July 30, 2020, 6:53 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1594723868 -19800
#      Tue Jul 14 16:21:08 2020 +0530
# Node ID 095b5d6b721c7068dd2e388e9b50fe3a29127eea
# Parent  f3f40eb3553885db4ff8a67e298602c842fceea1
# EXP-Topic merge-refactor
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

Patch

diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -217,6 +217,7 @@  class mercurial_sink(common.converter_si
         """
         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,
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -546,18 +546,21 @@  class mergeresult(object):
     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 @@  class mergeresult(object):
     def renamedelete(self):
         return self._renamedelete
 
+    @property
+    def commitinfo(self):
+        return self._commitinfo
+
     def setactions(self, actions):
         self._actions = actions
 
@@ -608,6 +615,10 @@  def manifestmerge(
     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 @@  def manifestmerge(
                             (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 @@  def manifestmerge(
                         (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 @@  def manifestmerge(
     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 @@  def calculateupdates(
             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)