evolve: extract function for relocating divergent commit
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 01 Apr 2020 09:21:29 -0700
changeset 5333 299d86c15b55
parent 5332 2570d2d4a268
child 5334 6e9c5aebe3d1
evolve: extract function for relocating divergent commit There was some duplication here, so let's extract to a function. I'm going to add a little bit more shared code next.
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py	Sun May 03 01:01:19 2020 +0200
+++ b/hgext3rd/evolve/evolvecmd.py	Wed Apr 01 09:21:29 2020 -0700
@@ -444,6 +444,11 @@
 
     return (True, divergent, other, resolutionparent, relocatereq)
 
+def _relocatedivergent(repo, orig, dest, evolvestate):
+    """relocates a divergent commit and saves the evolve state"""
+    with state.saver(evolvestate, {b'current': orig.node()}):
+        return _relocate(repo, orig, dest, evolvestate, keepbranch=True)
+
 def _solvedivergent(ui, repo, divergent, evolvestate, displayer, dryrun=False,
                     confirm=False, progresscb=None):
     """tries to solve content-divergence of a changeset
@@ -521,9 +526,8 @@
         evolvestate[b'relocating-div'] = True
         ui.status(_(b'rebasing "divergent" content-divergent changeset %s on'
                     b' %s\n' % (divergent, repo[succsdivp1])))
-        with state.saver(evolvestate, {b'current': divergent.node()}):
-            newdivergent = _relocate(repo, divergent, repo[succsdivp1],
-                                     evolvestate, keepbranch=True)
+        newdivergent = _relocatedivergent(repo, divergent, repo[succsdivp1],
+                                          evolvestate)
         evolvestate[b'old-divergent'] = divergent.node()
         divergent = repo[newdivergent]
         evolvestate[b'relocating-div'] = False
@@ -543,9 +547,7 @@
         evolvestate[b'relocating-other'] = True
         ui.status(_(b'rebasing "other" content-divergent changeset %s on'
                     b' %s\n' % (other, divergent.p1())))
-        with state.saver(evolvestate, {b'current': other.node()}):
-            newother = _relocate(repo, other, divergent.p1(), evolvestate,
-                                 keepbranch=True)
+        newother = _relocatedivergent(repo, other, divergent.p1(), evolvestate)
         evolvestate[b'old-other'] = other.node()
         other = repo[newother]
         evolvestate[b'relocating-other'] = False
@@ -2059,9 +2061,8 @@
                 evolvestate[b'relocating-other'] = True
                 ui.status(_(b'rebasing "other" content-divergent changeset %s on'
                             b' %s\n' % (other, divergent.p1())))
-                with state.saver(evolvestate, {b'current': other.node()}):
-                    newother = _relocate(repo, other, divergent.p1(),
-                                         evolvestate, keepbranch=True)
+                newother = _relocatedivergent(repo, other, divergent.p1(),
+                                              evolvestate)
                 evolvestate[b'old-other'] = other.node()
                 other = repo[newother]
                 evolvestate[b'relocating-other'] = False