evolve: handle interrupted phase-divergence resolution gracefully
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 24 Mar 2018 17:21:42 +0530
changeset 3633 ed3032ee53eb
parent 3632 8d38b88233cb
child 3634 a9fed41c6bed
evolve: handle interrupted phase-divergence resolution gracefully This patch adds logic to handle the interrupted phase-divergence resolution by `hg evolve` command gracefully. We first complete the relocation of the changeset and then do the divergence resolution. Previous functions moved required code separate fucntions so that we can use them here.
hgext3rd/evolve/evolvecmd.py
tests/test-evolve-phase-divergence.t
--- a/hgext3rd/evolve/evolvecmd.py	Sat Mar 24 16:41:14 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sat Mar 24 17:21:42 2018 +0530
@@ -1242,6 +1242,8 @@
         if (evolvestate['command'] == 'next' or
             evolvestate['category'] == 'orphan'):
             _completeorphan(ui, repo, evolvestate)
+        elif evolvestate['category'] == 'phasedivergent':
+            _completephasedivergent(ui, repo, evolvestate)
         else:
             repo.ui.status(_("continuing interrupted '%s' resolution is not yet"
                              " supported\n") % evolvestate['category'])
@@ -1265,6 +1267,31 @@
                         evolvestate['skippedrevs'].append(curctx.node())
         return
 
+def _completephasedivergent(ui, repo, evolvestate):
+    """function to complete the interrupted phase-divergence resolution.
+
+    First completes the relocation of the commit and then process resolving
+    phase-divergence"""
+
+    tr = None
+    try:
+        # need to start transaction for bookmark changes
+        tr = repo.transaction('evolve')
+        node = _completerelocation(ui, repo, evolvestate)
+        # resolving conflicts can lead to empty wdir and node can be None in
+        # those cases
+        ctx = repo[evolvestate['current']]
+        newctx = repo[node] if node is not None else repo['.']
+        compat.createmarkers(repo, [(ctx, (newctx,))], operation='evolve')
+
+        # now continuing the phase-divergence resolution part
+        prec = repo[evolvestate['precursor']]
+        _resolvephasedivergent(ui, repo, prec, ctx, newctx)
+        evolvestate['replacements'][ctx.node()] = node
+        tr.close()
+    finally:
+        tr.release()
+
 def _completeorphan(ui, repo, evolvestate):
     """function to complete the interrupted orphan resolution"""
 
--- a/tests/test-evolve-phase-divergence.t	Sat Mar 24 16:41:14 2018 +0530
+++ b/tests/test-evolve-phase-divergence.t	Sat Mar 24 17:21:42 2018 +0530
@@ -814,24 +814,23 @@
   (no more unresolved files)
   continue: hg evolve --continue
 
-XXX: we should handle this correctly here, this is not phase-divergence
-resolution happening
-
   $ hg evolve --continue
-  continuing interrupted 'phasedivergent' resolution is not yet supported
-  working directory is now at 8c2bb6fb44e9
+  evolving 19:5fd38c0de46e "added l to l"
+  computing new diff
+  committed as e3090241a10c
+  working directory is now at e3090241a10c
 
   $ hg glog
-  *  19:5fd38c0de46e added l to l
+  @  21:e3090241a10c phase-divergent update to f3794e5a91dc:
   |   () draft
-  | o  17:f3794e5a91dc added l to l
-  | |   () 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  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
   o  8:502e73736632 phase-divergent update to b756eb10ea73:
   |   () public
   o  6:b756eb10ea73 added bar to bar
@@ -844,3 +843,27 @@
   |   () public
   o  0:d3873e73d99e init
       () public
+
+  $ hg exp
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
+  # Node ID e3090241a10c320b6132e4673915fd6b19c0de39
+  # Parent  f3794e5a91dc1d4d36fee5c423386b19433a1f48
+  phase-divergent update to f3794e5a91dc:
+  
+  added l to l
+  
+  diff -r f3794e5a91dc -r e3090241a10c l
+  --- a/l	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/l	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,1 +1,1 @@
+  -l
+  +kl
+  diff -r f3794e5a91dc -r e3090241a10c x
+  --- a/x	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/x	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,1 +1,1 @@
+  -x
+  +foo