bookmark: split out target computation from 'deletedivergent'
authorBoris Feld <boris.feld@octobus.net>
Mon, 10 Jul 2017 19:08:17 +0200
changeset 33510 07b556d1b74e
parent 33509 a3acacbd0ff3
child 33511 9689239d7c2b
bookmark: split out target computation from 'deletedivergent' We want to use applychanges in order to unify bookmark movement. We need a way to compute divergence deletion without actually removing them. We split the function in two in this patch while we migrate the existing users of this code on next patches.
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Mon Jul 10 17:48:33 2017 +0200
+++ b/mercurial/bookmarks.py	Mon Jul 10 19:08:17 2017 +0200
@@ -294,7 +294,17 @@
     '''Delete divergent versions of bm on nodes in deletefrom.
 
     Return True if at least one bookmark was deleted, False otherwise.'''
-    deleted = False
+    bms = divergent2delete(repo, deletefrom, bm)
+    marks = repo._bookmarks
+    for b in bms:
+        del marks[b]
+    return bool(bms)
+
+def divergent2delete(repo, deletefrom, bm):
+    """find divergent versions of bm on nodes in deletefrom.
+
+    the list of bookmark to delete."""
+    todelete = []
     marks = repo._bookmarks
     divergent = [b for b in marks if b.split('@', 1)[0] == bm.split('@', 1)[0]]
     for mark in divergent:
@@ -303,9 +313,8 @@
             continue
         if mark and marks[mark] in deletefrom:
             if mark != bm:
-                del marks[mark]
-                deleted = True
-    return deleted
+                todelete.append(mark)
+    return todelete
 
 def headsforactive(repo):
     """Given a repo with an active bookmark, return divergent bookmark nodes.