Patchwork [2,of,2,evolve-ext] evolve: extract logic to new method _finalizerelocate

login
register
mail settings
Submitter Shusen LIU
Date Dec. 15, 2015, 1:26 a.m.
Message ID <0ce293362d9b8536cc0c.1450142812@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12047/
State Accepted
Delegated to: Laurent Charignon
Headers show

Comments

Shusen LIU - Dec. 15, 2015, 1:26 a.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1450142471 28800
#      Mon Dec 14 17:21:11 2015 -0800
# Node ID 0ce293362d9b8536cc0cd01568b168352be948a6
# Parent  0f231df1aba960973ae8cd1536632f63cb55372a
evolve: extract logic to new method _finalizerelocate

This patch introduces a new method _finalizerelocate to finalize current state
after merge states in relocate method.
This simplifies the code of the method relocate and allows us to modify it
later to support a continued keywork to implement evolve state.
Laurent Charignon - Dec. 15, 2015, 1:41 a.m.
Hi,

These two patches look good to me and offer useful refactoring with the
goal of having a separate evolve state.
Pierre-Yves, feel free to review and push them to main if it works for you.

Thanks,

Laurent

On 12/14/15, 5:26 PM, "Mercurial-devel on behalf of Shusen LIU"
<mercurial-devel-bounces@selenic.com on behalf of liushusen@fb.com> wrote:

># HG changeset patch
># User Shusen LIU <liushusen@fb.com>
># Date 1450142471 28800
>#      Mon Dec 14 17:21:11 2015 -0800
># Node ID 0ce293362d9b8536cc0cd01568b168352be948a6
># Parent  0f231df1aba960973ae8cd1536632f63cb55372a
>evolve: extract logic to new method _finalizerelocate
>
>This patch introduces a new method _finalizerelocate to finalize current
>state
>after merge states in relocate method.
>This simplifies the code of the method relocate and allows us to modify 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
>@@ -966,20 +966,7 @@
>             exc.__class__ = LocalMergeFailure
>             raise
>         oldbookmarks = repo.nodebookmarks(nodesrc)
>-        if nodenew is not None:
>-            phases.retractboundary(repo, tr, destphase, [nodenew])
>-            obsolete.createmarkers(repo, [(repo[nodesrc],
>(repo[nodenew],))])
>-            for book in oldbookmarks:
>-                repo._bookmarks[book] = nodenew
>-        else:
>-            obsolete.createmarkers(repo, [(repo[nodesrc], ())])
>-            # Behave like rebase, move bookmarks to dest
>-            for book in oldbookmarks:
>-                repo._bookmarks[book] = dest.node()
>-        for book in destbookmarks: # restore bookmark that rebase move
>-            repo._bookmarks[book] = dest.node()
>-        if oldbookmarks or destbookmarks:
>-            repo._bookmarks.recordchange(tr)
>+        _finalizerelocate(repo, orig, dest, nodenew, tr)
>         tr.close()
>     finally:
>         tr.release()
>@@ -3675,3 +3662,23 @@
>     finally:
>         repo.ui.restoreconfig(backup)
>     return nodenew
>+
>+def _finalizerelocate(repo, orig, dest, nodenew, tr):
>+    destbookmarks = repo.nodebookmarks(dest.node())
>+    nodesrc = orig.node()
>+    destphase = repo[nodesrc].phase()
>+    oldbookmarks = repo.nodebookmarks(nodesrc)
>+    if nodenew is not None:
>+        phases.retractboundary(repo, tr, destphase, [nodenew])
>+        obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
>+        for book in oldbookmarks:
>+            repo._bookmarks[book] = nodenew
>+    else:
>+        obsolete.createmarkers(repo, [(repo[nodesrc], ())])
>+        # Behave like rebase, move bookmarks to dest
>+        for book in oldbookmarks:
>+            repo._bookmarks[book] = dest.node()
>+    for book in destbookmarks: # restore bookmark that rebase move
>+        repo._bookmarks[book] = dest.node()
>+    if oldbookmarks or destbookmarks:
>+        repo._bookmarks.recordchange(tr)
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel@selenic.com
>https://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Dec. 17, 2015, 4:23 p.m.
On 12/15/2015 01:41 AM, Laurent Charignon wrote:
> Hi,
>
> These two patches look good to me and offer useful refactoring with the
> goal of having a separate evolve state.
> Pierre-Yves, feel free to review and push them to main if it works for you.

I've pushed these two, thanks.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -966,20 +966,7 @@ 
             exc.__class__ = LocalMergeFailure
             raise
         oldbookmarks = repo.nodebookmarks(nodesrc)
-        if nodenew is not None:
-            phases.retractboundary(repo, tr, destphase, [nodenew])
-            obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
-            for book in oldbookmarks:
-                repo._bookmarks[book] = nodenew
-        else:
-            obsolete.createmarkers(repo, [(repo[nodesrc], ())])
-            # Behave like rebase, move bookmarks to dest
-            for book in oldbookmarks:
-                repo._bookmarks[book] = dest.node()
-        for book in destbookmarks: # restore bookmark that rebase move
-            repo._bookmarks[book] = dest.node()
-        if oldbookmarks or destbookmarks:
-            repo._bookmarks.recordchange(tr)
+        _finalizerelocate(repo, orig, dest, nodenew, tr)
         tr.close()
     finally:
         tr.release()
@@ -3675,3 +3662,23 @@ 
     finally:
         repo.ui.restoreconfig(backup)
     return nodenew
+
+def _finalizerelocate(repo, orig, dest, nodenew, tr):
+    destbookmarks = repo.nodebookmarks(dest.node())
+    nodesrc = orig.node()
+    destphase = repo[nodesrc].phase()
+    oldbookmarks = repo.nodebookmarks(nodesrc)
+    if nodenew is not None:
+        phases.retractboundary(repo, tr, destphase, [nodenew])
+        obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
+        for book in oldbookmarks:
+            repo._bookmarks[book] = nodenew
+    else:
+        obsolete.createmarkers(repo, [(repo[nodesrc], ())])
+        # Behave like rebase, move bookmarks to dest
+        for book in oldbookmarks:
+            repo._bookmarks[book] = dest.node()
+    for book in destbookmarks: # restore bookmark that rebase move
+        repo._bookmarks[book] = dest.node()
+    if oldbookmarks or destbookmarks:
+        repo._bookmarks.recordchange(tr)