evolve: move logic to complete interrupted orphan resolution to new fn
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 24 Mar 2018 12:58:12 +0530
changeset 3629 f23946bf6625
parent 3628 170b99a9c0b4
child 3630 2789c0ec2ad7
evolve: move logic to complete interrupted orphan resolution to new fn This patch moves logic which completes an interrupted orphan resolution to it's own new function. We will defining such functions for completing phase-divergence and content-divergence too.
hgext3rd/evolve/evolvecmd.py
tests/test-evolve-phase-divergence.t
--- a/hgext3rd/evolve/evolvecmd.py	Fri Mar 23 19:36:08 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sat Mar 24 12:58:12 2018 +0530
@@ -1231,76 +1231,21 @@
 
 def continueevolve(ui, repo, evolvestate, progresscb):
     """logic for handling of `hg evolve --continue`"""
-    orig = repo[evolvestate['current']]
+
     with repo.wlock(), repo.lock():
-        ctx = orig
-        source = ctx.extra().get('source')
-        extra = {}
-        if source:
-            extra['source'] = source
-            extra['intermediate-source'] = ctx.hex()
+        if (evolvestate['command'] == 'next' or
+            evolvestate['category'] == 'orphan'):
+            _completeorphan(ui, repo, evolvestate)
         else:
-            extra['source'] = ctx.hex()
-        user = ctx.user()
-        date = ctx.date()
-        message = ctx.description()
-        ui.status(_('evolving %d:%s "%s"\n') % (ctx.rev(), ctx,
-                                                message.split('\n', 1)[0]))
-        targetphase = max(ctx.phase(), phases.draft)
-        overrides = {('phases', 'new-commit'): targetphase}
-
-        ctxparents = orig.parents()
-        if len(ctxparents) == 2:
-            currentp1 = repo.dirstate.parents()[0]
-            p1obs = ctxparents[0].obsolete()
-            p2obs = ctxparents[1].obsolete()
-            # asumming that the parent of current wdir is successor of one
-            # of p1 or p2 of the original changeset
-            if p1obs and not p2obs:
-                # p1 is obsolete and p2 is not obsolete, current working
-                # directory parent should be successor of p1, so we should
-                # set dirstate parents to (succ of p1, p2)
-                with repo.dirstate.parentchange():
-                    repo.dirstate.setparents(currentp1,
-                                             ctxparents[1].node())
-            elif p2obs and not p1obs:
-                # p2 is obsolete and p1 is not obsolete, current working
-                # directory parent should be successor of p2, so we should
-                # set dirstate parents to (succ of p2, p1)
-                with repo.dirstate.parentchange():
-                    repo.dirstate.setparents(ctxparents[0].node(),
-                                             currentp1)
-
-            else:
-                # both the parents were obsoleted, if orphanmerge is set, we
-                # are processing the second parent first (to keep parent order)
-                if evolvestate.get('orphanmerge'):
-                    with repo.dirstate.parentchange():
-                        repo.dirstate.setparents(ctxparents[0].node(),
-                                                 currentp1)
-                pass
-
-        with repo.ui.configoverride(overrides, 'evolve-continue'):
-            node = repo.commit(text=message, user=user,
-                               date=date, extra=extra)
-
-        # resolving conflicts can lead to empty wdir and node can be None in
-        # those cases
-        newctx = repo[node] if node is not None else repo['.']
-        compat.createmarkers(repo, [(ctx, (newctx,))], operation='evolve')
+            repo.ui.status(_("continuing interrupted '%s' resolution is not yet"
+                             " supported\n") % evolvestate['category'])
+            return
 
         # make sure we are continuing evolve and not `hg next --evolve`
         if evolvestate['command'] == 'evolve':
-            evolvestate['replacements'][ctx.node()] = node
             category = evolvestate['category']
             confirm = evolvestate['confirm']
             unfi = repo.unfiltered()
-            if evolvestate['orphanmerge']:
-                # processing a merge changeset with both parents obsoleted,
-                # stabilized on second parent, insert in front of list to
-                # re-process to stabilize on first parent
-                evolvestate['revs'].insert(0, repo[node].rev())
-                evolvestate['orphanmerge'] = False
             for rev in evolvestate['revs']:
                 # XXX: prevent this lookup by storing nodes instead of revnums
                 curctx = unfi[rev]
@@ -1313,3 +1258,73 @@
                     else:
                         evolvestate['skippedrevs'].append(curctx.node())
         return
+
+def _completeorphan(ui, repo, evolvestate):
+    """function to complete the interrupted orphan resolution"""
+
+    orig = repo[evolvestate['current']]
+    ctx = orig
+    source = ctx.extra().get('source')
+    extra = {}
+    if source:
+        extra['source'] = source
+        extra['intermediate-source'] = ctx.hex()
+    else:
+        extra['source'] = ctx.hex()
+    user = ctx.user()
+    date = ctx.date()
+    message = ctx.description()
+    ui.status(_('evolving %d:%s "%s"\n') % (ctx.rev(), ctx,
+                                            message.split('\n', 1)[0]))
+    targetphase = max(ctx.phase(), phases.draft)
+    overrides = {('phases', 'new-commit'): targetphase}
+
+    ctxparents = orig.parents()
+    if len(ctxparents) == 2:
+        currentp1 = repo.dirstate.parents()[0]
+        p1obs = ctxparents[0].obsolete()
+        p2obs = ctxparents[1].obsolete()
+        # asumming that the parent of current wdir is successor of one
+        # of p1 or p2 of the original changeset
+        if p1obs and not p2obs:
+            # p1 is obsolete and p2 is not obsolete, current working
+            # directory parent should be successor of p1, so we should
+            # set dirstate parents to (succ of p1, p2)
+            with repo.dirstate.parentchange():
+                repo.dirstate.setparents(currentp1,
+                                         ctxparents[1].node())
+        elif p2obs and not p1obs:
+            # p2 is obsolete and p1 is not obsolete, current working
+            # directory parent should be successor of p2, so we should
+            # set dirstate parents to (succ of p2, p1)
+            with repo.dirstate.parentchange():
+                repo.dirstate.setparents(ctxparents[0].node(),
+                                         currentp1)
+
+        else:
+            # both the parents were obsoleted, if orphanmerge is set, we
+            # are processing the second parent first (to keep parent order)
+            if evolvestate.get('orphanmerge'):
+                with repo.dirstate.parentchange():
+                    repo.dirstate.setparents(ctxparents[0].node(),
+                                             currentp1)
+            pass
+
+    with repo.ui.configoverride(overrides, 'evolve-continue'):
+        node = repo.commit(text=message, user=user,
+                           date=date, extra=extra)
+
+    # resolving conflicts can lead to empty wdir and node can be None in
+    # those cases
+    newctx = repo[node] if node is not None else repo['.']
+    compat.createmarkers(repo, [(ctx, (newctx,))], operation='evolve')
+
+    # make sure we are continuing evolve and not `hg next --evolve`
+    if evolvestate['command'] == 'evolve':
+        evolvestate['replacements'][ctx.node()] = node
+        if evolvestate['orphanmerge']:
+            # processing a merge changeset with both parents obsoleted,
+            # stabilized on second parent, insert in front of list to
+            # re-process to stabilize on first parent
+            evolvestate['revs'].insert(0, repo[node].rev())
+            evolvestate['orphanmerge'] = False
--- a/tests/test-evolve-phase-divergence.t	Fri Mar 23 19:36:08 2018 +0530
+++ b/tests/test-evolve-phase-divergence.t	Sat Mar 24 12:58:12 2018 +0530
@@ -818,20 +818,20 @@
 resolution happening
 
   $ hg evolve --continue
-  evolving 19:5fd38c0de46e "added l to l"
-  working directory is now at 2598cf6ceb65
+  continuing interrupted 'phasedivergent' resolution is not yet supported
+  working directory is now at 8c2bb6fb44e9
 
   $ hg glog
-  @  20:2598cf6ceb65 added l to l
+  *  19:5fd38c0de46e added l to l
   |   () draft
   | o  17:f3794e5a91dc added l to l
-  |/    () public
-  o  16:8c2bb6fb44e9 phase-divergent update to dc88f5aa9bc9:
-  |   () public
-  o  12:dc88f5aa9bc9 y to y and foobar to foo
-  |   () public
-  o  9:2352021b3785 added x to x
-  |   (bm) public
+  | |   () public
+  | @  16:8c2bb6fb44e9 phase-divergent update to dc88f5aa9bc9:
+  | |   () public
+  | o  12:dc88f5aa9bc9 y to y and foobar to foo
+  | |   () public
+  | o  9:2352021b3785 added x to x
+  |/    (bm) public
   o  8:502e73736632 phase-divergent update to b756eb10ea73:
   |   () public
   o  6:b756eb10ea73 added bar to bar