changeset 22902:ce0592328d68

merge: add merge.graft helper This will help unify all the open-coded graft/rebase operations.
author Matt Mackall <mpm@selenic.com>
date Mon, 13 Oct 2014 17:12:12 -0500
parents 722117c8e023
children 3d51e756b1ec
files mercurial/merge.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Oct 13 14:33:13 2014 -0500
+++ b/mercurial/merge.py	Mon Oct 13 17:12:12 2014 -0500
@@ -1149,3 +1149,29 @@
     if not partial:
         repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
     return stats
+
+def graft(repo, ctx, pctx, labels):
+    """Do a graft-like merge.
+
+    This is a merge where the merge ancestor is chosen such that one
+    or more changesets are grafted onto the current changeset. In
+    addition to the merge, this fixes up the dirstate to include only
+    a single parent and tries to duplicate any renames/copies
+    appropriately.
+
+    ctx - changeset to rebase
+    pctx - merge base, usually ctx.p1()
+    labels - merge labels eg ['local', 'graft']
+
+    """
+
+    stats = update(repo, ctx.node(), True, True, False, pctx.node(),
+                   labels=labels)
+    # drop the second merge parent
+    repo.dirstate.beginparentchange()
+    repo.setparents(repo['.'].node(), nullid)
+    repo.dirstate.write()
+    # fix up dirstate for copies and renames
+    copies.duplicatecopies(repo, ctx.rev(), pctx.rev())
+    repo.dirstate.endparentchange()
+    return stats