strip: extract bookmark movement into a separate function
authorBoris Feld <boris.feld@octobus.net>
Wed, 02 Jan 2019 05:12:07 +0100
changeset 41102 c9a2c4d0e80f
parent 41101 f04e0ca04099
child 41103 86f0ed7ac688
strip: extract bookmark movement into a separate function We will need it for the soft-strip case.
mercurial/repair.py
--- a/mercurial/repair.py	Wed Jan 02 05:07:03 2019 +0100
+++ b/mercurial/repair.py	Wed Jan 02 05:12:07 2019 +0100
@@ -153,22 +153,7 @@
         stripobsidx = [i for i, m in enumerate(repo.obsstore)
                        if m in obsmarkers]
 
-    # compute necessary bookmark movement
-    bm = repo._bookmarks
-    updatebm = []
-    for m in bm:
-        rev = repo[bm[m]].rev()
-        if rev in tostrip:
-            updatebm.append(m)
-    newbmtarget = None
-    if updatebm: # don't compute anything is there is no bookmark to move anyway
-        # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)),
-        # but is much faster
-        newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip)
-        if newbmtarget:
-            newbmtarget = repo[newbmtarget.first()].node()
-        else:
-            newbmtarget = '.'
+    newbmtarget, updatebm = _bookmarkmovements(repo, tostrip)
 
     backupfile = None
     node = nodelist[-1]
@@ -235,7 +220,7 @@
 
             with repo.transaction('repair') as tr:
                 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
-                bm.applychanges(repo, tr, bmchanges)
+                repo._bookmarks.applychanges(repo, tr, bmchanges)
 
             # remove undo files
             for undovfs, undofile in repo.undofiles():
@@ -267,6 +252,25 @@
     # extensions can use it
     return backupfile
 
+def _bookmarkmovements(repo, tostrip):
+    # compute necessary bookmark movement
+    bm = repo._bookmarks
+    updatebm = []
+    for m in bm:
+        rev = repo[bm[m]].rev()
+        if rev in tostrip:
+            updatebm.append(m)
+    newbmtarget = None
+    if updatebm: # don't compute anything is there is no bookmark to move anyway
+        # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)),
+        # but is much faster
+        newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip)
+        if newbmtarget:
+            newbmtarget = repo[newbmtarget.first()].node()
+        else:
+            newbmtarget = '.'
+    return newbmtarget, updatebm
+
 def _createstripbackup(repo, stripbases, node, topic):
     # backup the changeset we are about to strip
     vfs = repo.vfs