evolve: restore bookmarks correctly after `hg evolve --abort`
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 29 Mar 2018 17:34:51 +0530
changeset 3653 d9682c41ea2f
parent 3652 81985b9d3e74
child 3654 23e515ca0143
evolve: restore bookmarks correctly after `hg evolve --abort` This patch adds logic to store bookmark movements in evolvestate class and restore bookmarks to their original place if `hg evolve --abort` is called.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/evolvecmd.py
tests/test-evolve-abort.t
--- a/hgext3rd/evolve/__init__.py	Thu Mar 29 17:42:32 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Thu Mar 29 17:34:51 2018 +0530
@@ -1164,7 +1164,8 @@
     """logic for hg next command to evolve and update to an aspiring children"""
 
     cmdutil.bailifchanged(repo)
-    evolvestate = state.cmdstate(repo, opts={'command': 'next'})
+    evolvestate = state.cmdstate(repo, opts={'command': 'next',
+                                             'bookmarkchanges': []})
     result = evolvecmd._solveone(ui, repo, repo[aspchildren],
                                  evolvestate, opts.get('dry_run'), False,
                                  lambda: None, category='orphan')
--- a/hgext3rd/evolve/evolvecmd.py	Thu Mar 29 17:42:32 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Thu Mar 29 17:34:51 2018 +0530
@@ -581,6 +581,7 @@
                              operation='evolve')
         for book in oldbookmarks:
             bmchanges.append((book, nodenew))
+            evolvestate['bookmarkchanges'].append((book, nodesrc))
     else:
         if category == 'orphan':
             repo.ui.status(_("evolution of %d:%s created no changes "
@@ -588,6 +589,7 @@
         compat.createmarkers(repo, [(repo[nodesrc], ())], operation='evolve')
         # Behave like rebase, move bookmarks to dest
         for book in oldbookmarks:
+            evolvestate['bookmarkchanges'].append((book, nodesrc))
             bmchanges.append((book, dest.node()))
     for book in destbookmarks: # restore bookmark that rebase move
         bmchanges.append((book, dest.node()))
@@ -1242,7 +1244,8 @@
         stateopts = {'category': targetcat, 'replacements': {},
                      'revs': list(revs), 'confirm': confirmopt,
                      'startnode': startnode.node(), 'skippedrevs': [],
-                     'command': 'evolve', 'orphanmerge': False}
+                     'command': 'evolve', 'orphanmerge': False,
+                     'bookmarkchanges': []}
         evolvestate.addopts(stateopts)
         for rev in revs:
             curctx = repo[rev]
@@ -1312,6 +1315,17 @@
                 # no backup of evolved cset versions needed
                 repair.strip(repo.ui, repo, strippoints, False)
 
+            tr = None
+            try:
+                tr = repo.transaction('evolve')
+                # restoring bookmarks at there original place
+                bmchanges = evolvestate['bookmarkchanges']
+                if bmchanges:
+                    compat.bookmarkapplychanges(repo, tr, bmchanges)
+                tr.close()
+            finally:
+                tr.release()
+
             evolvestate.delete()
             ui.status(_('evolve aborted\n'))
             ui.status(_('working directory is now at %s\n')
--- a/tests/test-evolve-abort.t	Thu Mar 29 17:42:32 2018 +0530
+++ b/tests/test-evolve-abort.t	Thu Mar 29 17:34:51 2018 +0530
@@ -485,14 +485,13 @@
   evolve aborted
   working directory is now at a0086c17bfc7
 
-XXX: the bookmark bm1 should have moved back to 9f0c80a55ddc
   $ hg glog
   @  4:a0086c17bfc7 added a
-  |   (bm1) draft
+  |   () draft
   | *  3:17509928e5bf added c
   | |   () draft
   | *  2:9f0c80a55ddc added b
-  | |   () draft
+  | |   (bm1) draft
   | x  1:2f913b0c9220 added a
   |/    () draft
   o  0:8fa14d15e168 added hgignore