# HG changeset patch # User Shusen LIU # Date 1453851721 28800 # Node ID f157ef7b17411553e100089245c43c0a4bbe41b1 # Parent 5b34513d1117e0671ea139b8aa994608ab3acab0 evolve: extract logic to new method _evolvemerge This patch introduces a new method _evolvemerge to merge orig to dest in relocate method. This simplifies the code of the method relocate and allows us to re-use it later in the scope of the rework of 'hg evolve --continue' diff -r 5b34513d1117 -r f157ef7b1741 hgext/evolve.py --- a/hgext/evolve.py Sat Jan 30 16:53:12 2016 +0100 +++ b/hgext/evolve.py Tue Jan 26 15:42:01 2016 -0800 @@ -949,26 +949,7 @@ tr = repo.transaction('relocate') try: try: - if repo['.'].rev() != dest.rev(): - merge.update(repo, dest, False, True, False) - if bmactive(repo): - repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo)) - bmdeactivate(repo) - if keepbranch: - repo.dirstate.setbranch(orig.branch()) - - try: - r = merge.graft(repo, orig, pctx, ['local', 'graft'], True) - except TypeError: - # not using recent enough mercurial - if len(orig.parents()) == 2: - raise error.Abort( - _("no support for evolving merge changesets yet"), - hint=_("Redo the merge and use `hg prune --succ " - "` to obsolete the old one")) - - r = merge.graft(repo, orig, pctx, ['local', 'graft']) - + r = _evolvemerge(repo, orig, dest, pctx, keepbranch) if r[-1]: #some conflict raise error.Abort( 'unresolved merge conflicts (see hg help resolve)') @@ -3754,3 +3735,27 @@ repo._bookmarks[book] = dest.node() if oldbookmarks or destbookmarks: repo._bookmarks.recordchange(tr) + +def _evolvemerge(repo, orig, dest, pctx, keepbranch): + """Used by the evolve function to merge dest on top of pctx. + return the same tuple as merge.graft""" + if repo['.'].rev() != dest.rev(): + merge.update(repo, dest, False, True, False) + if bmactive(repo): + repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo)) + bmdeactivate(repo) + if keepbranch: + repo.dirstate.setbranch(orig.branch()) + + try: + r = merge.graft(repo, orig, pctx, ['local', 'graft'], True) + except TypeError: + # not using recent enough mercurial + if len(orig.parents()) == 2: + raise error.Abort( + _("no support for evolving merge changesets yet"), + hint=_("Redo the merge and use `hg prune --succ " + "` to obsolete the old one")) + + r = merge.graft(repo, orig, pctx, ['local', 'graft']) + return r