Patchwork [02,of,10] bookmark: split out target computation from 'deletedivergent'

login
register
mail settings
Submitter Boris Feld
Date July 15, 2017, 11:42 a.m.
Message ID <95035db0c9c8e55bf751.1500118970@FB>
Download mbox | patch
Permalink /patch/22395/
State Accepted
Headers show

Comments

Boris Feld - July 15, 2017, 11:42 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499706497 -7200
#      Mon Jul 10 19:08:17 2017 +0200
# Node ID 95035db0c9c8e55bf75165d098e38286784e4a6c
# Parent  982526b815da34df7d0335b246afcbe48df3d112
# EXP-Topic tr.changes.bookmarks
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.

Patch

diff -r 982526b815da -r 95035db0c9c8 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.