Patchwork [5,of,7] strip: extract bookmark movement into a separate function

login
register
mail settings
Submitter Boris Feld
Date Jan. 2, 2019, 10:35 p.m.
Message ID <65488c7d2e933cdb2ab1.1546468553@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/37429/
State Accepted
Headers show

Comments

Boris Feld - Jan. 2, 2019, 10:35 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1546402327 -3600
#      Wed Jan 02 05:12:07 2019 +0100
# Node ID 65488c7d2e933cdb2ab1c36b3887a8a67a24fc60
# Parent  b2a59d144ba0849db8302ce92123b70cb2ba2dc6
# EXP-Topic archived-phase-UX
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 65488c7d2e93
strip: extract bookmark movement into a separate function

We will need it for the soft-strip case.
Pulkit Goyal - Jan. 3, 2019, 11:12 a.m.
On Thu, Jan 3, 2019 at 4:16 AM Boris Feld <boris.feld@octobus.net> wrote:

> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1546402327 -3600
> #      Wed Jan 02 05:12:07 2019 +0100
> # Node ID 65488c7d2e933cdb2ab1c36b3887a8a67a24fc60
> # Parent  b2a59d144ba0849db8302ce92123b70cb2ba2dc6
> # EXP-Topic archived-phase-UX
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 65488c7d2e93
> strip: extract bookmark movement into a separate function
>
> We will need it for the soft-strip case.
>

Queued upto here i.e. 1-5. Many thanks for taking out time and working on
this. \o/

Patch

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -153,22 +153,7 @@  def strip(ui, repo, nodelist, backup=Tru
         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 @@  def strip(ui, repo, nodelist, backup=Tru
 
             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 @@  def strip(ui, repo, nodelist, backup=Tru
     # 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