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

login
register
mail settings
Submitter Shusen LIU
Date Jan. 26, 2016, 11:42 p.m.
Message ID <5b06d730249ea418ee27.1453851773@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12890/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Shusen LIU - Jan. 26, 2016, 11:42 p.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1453851721 28800
#      Tue Jan 26 15:42:01 2016 -0800
# Node ID 5b06d730249ea418ee274f4bcf00fb9056fad27f
# Parent  ea7523380efa894213582ca1600dc472baa7b25e
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.
Bryan O'Sullivan - Jan. 27, 2016, 12:12 a.m.
On Tue, Jan 26, 2016 at 3:42 PM, Shusen LIU <liushusen@fb.com> wrote:

> +    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
>

Just as a small matter of code hygiene, I would prefer to see two return
statements instead of assignments followed by a return. That makes more
sense now that you've extracted this out into its own function.

Also, I am not sure what "support a continued keywork" in your description
means.
Pierre-Yves David - Jan. 30, 2016, 3:58 p.m.
On 01/27/2016 01:12 AM, Bryan O'Sullivan wrote:
>
> On Tue, Jan 26, 2016 at 3:42 PM, Shusen LIU <liushusen@fb.com
> <mailto:liushusen@fb.com>> wrote:
>
>     +    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
>
>
> Just as a small matter of code hygiene, I would prefer to see two return
> statements instead of assignments followed by a return. That makes more
> sense now that you've extracted this out into its own function.

Shusen, can you followup with a cleanup for that?

>
> Also, I am not sure what "support a continued keywork" in your
> description means.

I've updated that to:

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'


Because I think this is what it means.


Pushed to main otherwise.

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,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 <old> --succ "
+                      "<new>` to obsolete the old one"))
+
+       r = merge.graft(repo, orig, pctx, ['local', 'graft'])
+    return r