Patchwork D7177: [PoC] allow providing explicit mapping for parents of merge commits

login
register
mail settings
Submitter phabricator
Date Oct. 28, 2019, 4:17 p.m.
Message ID <differential-rev-PHID-DREV-mmfkz365brbciro7hgve-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42608/
State New
Headers show

Comments

phabricator - Oct. 28, 2019, 4:17 p.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: martinvonz.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Consider the following DAG:
  
  C   C'
  
  | \ / |
  |
  
  A B D
  
  with the goal of rebasing C to C' while switching the A parent to D.
  This can happen when dealing with manual rebases of merges without
  obsolescence markers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/rebase.py

CHANGE DETAILS




To: joerg.sonnenberger, martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 30, 2019, 5:38 a.m.
martinvonz added a comment.


  I changed the commit message to indent the graph by two spaces. That way it renders better here in Phabricator.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7177/new/

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

To: joerg.sonnenberger, martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -189,6 +189,13 @@ 
         self.activebookmark = None
         self.destmap = {}
         self.skipped = set()
+        self.parentmap = {}
+        for pm in opts.get(b'parentmap', []):
+            if pm.count(':') != 1:
+                raise error.Abort(_(b"--parentmap takes a pair of revisions"
+                                    b"separated by colon"))
+            oldp, newp = pm.split(":")
+            self.parentmap[int(oldp)] = int(newp)
 
         self.collapsef = opts.get(b'collapse', False)
         self.collapsemsg = cmdutil.logmessage(ui, opts)
@@ -614,6 +621,7 @@ 
                 self.state,
                 self.skipped,
                 self.obsoletenotrebased,
+                self.parentmap,
             )
             if not self.inmemory and len(repo[None].parents()) == 2:
                 repo.ui.debug(b'resuming interrupted rebase\n')
@@ -870,6 +878,7 @@ 
             _(b'read collapse commit message from file'),
             _(b'FILE'),
         ),
+        (b'p', b'parentmap', [], _(b'map old parent to new parent'), _(b'REV:REV')),
         (b'k', b'keep', False, _(b'keep original changesets')),
         (b'', b'keepbranches', False, _(b'keep original branch names')),
         (b'D', b'detach', False, _(b'(DEPRECATED)')),
@@ -1649,7 +1658,7 @@ 
             yield nodemap[s]
 
 
-def defineparents(repo, rev, destmap, state, skipped, obsskipped):
+def defineparents(repo, rev, destmap, state, skipped, obsskipped, parentmap):
     """Return new parents and optionally a merge base for rev being rebased
 
     The destination specified by "dest" cannot always be used directly because
@@ -1707,6 +1716,8 @@ 
                 np = dests[i]
             elif p in state and state[p] > 0:
                 np = state[p]
+            elif p in parentmap:
+                np = parentmap[p]
 
             # "bases" only record "special" merge bases that cannot be
             # calculated from changelog DAG (i.e. isancestor(p, np) is False).