Patchwork [evolve-ext-V4] evolve: extract logic to new method _evolvemerge

login
register
mail settings
Submitter Shusen LIU
Date Jan. 19, 2016, 8:04 p.m.
Message ID <610ee0a709186c3f42a2.1453233849@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12835/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Shusen LIU - Jan. 19, 2016, 8:04 p.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1453233597 28800
#      Tue Jan 19 11:59:57 2016 -0800
# Node ID 610ee0a709186c3f42a2c6f13669f87f5236c87d
# Parent  91e67ad4cb6c783fa1a32e03359aa6d73c765129
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 to support a continued keywork to implement evolve state.
Pierre-Yves David - Jan. 22, 2016, 6:49 p.m.
On 01/19/2016 12:04 PM, Shusen LIU wrote:
> # HG changeset patch
> # User Shusen LIU <liushusen@fb.com>
> # Date 1453233597 28800
> #      Tue Jan 19 11:59:57 2016 -0800
> # Node ID 610ee0a709186c3f42a2c6f13669f87f5236c87d
> # Parent  91e67ad4cb6c783fa1a32e03359aa6d73c765129
> 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 to support a continued keywork to implement evolve state.
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -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 <old> --succ "
> -                               "<new>` 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)')
> @@ -3723,3 +3704,25 @@
>           repo._bookmarks[book] = dest.node()
>       if oldbookmarks or destbookmarks:
>           repo._bookmarks.recordchange(tr)
> +
> +def _evolvemerge(repo, orig, dest, pctx, keepbranch):

Can I get you to document the scope and purpose of this method? Will 
help people to know where to put new code.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -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 <old> --succ "
-                               "<new>` 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)')
@@ -3723,3 +3704,25 @@ 
         repo._bookmarks[book] = dest.node()
     if oldbookmarks or destbookmarks:
         repo._bookmarks.recordchange(tr)
+
+def _evolvemerge(repo, orig, dest, pctx, keepbranch):
+    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 <old> --succ "
+                      "<new>` to obsolete the old one"))
+
+       r = merge.graft(repo, orig, pctx, ['local', 'graft'])
+    return r