Patchwork [2,of,3,stable] bookmarks: factor out delete divergent code

login
register
mail settings
Submitter Siddharth Agarwal
Date Jan. 31, 2013, 2:16 a.m.
Message ID <e651b86d041ea96809fa.1359598576@sid0x220>
Download mbox | patch
Permalink /patch/767/
State Accepted
Commit 37ce336ab2dd8d5adc32ec488027bc8f178d6c59
Headers show

Comments

Siddharth Agarwal - Jan. 31, 2013, 2:16 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1359588900 28800
# Branch stable
# Node ID e651b86d041ea96809fad36ee5ba886087ad2f75
# Parent  63c49a4df508562b8fd91a5da1b03b9fbadf08f8
bookmarks: factor out delete divergent code

Deleting divergent bookmarks is more generally useful than just in
bookmarks.update.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -156,6 +156,20 @@  def updatecurrentbookmark(repo, oldnode,
         else:
             raise util.Abort(_("branch %s not found") % curbranch)
 
+def deletedivergent(repo, deletefrom, bm):
+    '''Delete divergent versions of bm on nodes in deletefrom.
+
+    Return True if at least one bookmark was deleted, False otherwise.'''
+    deleted = False
+    marks = repo._bookmarks
+    divergent = [b for b in marks if b.split('@', 1)[0] == bm.split('@', 1)[0]]
+    for mark in divergent:
+        if mark and marks[mark] in deletefrom:
+            if mark != bm:
+                del marks[mark]
+                deleted = True
+    return deleted
+
 def update(repo, parents, node):
     marks = repo._bookmarks
     update = False
@@ -163,16 +177,16 @@  def update(repo, parents, node):
     if not cur:
         return False
 
-    toupdate = [b for b in marks if b.split('@', 1)[0] == cur.split('@', 1)[0]]
-    for mark in toupdate:
-        if mark and marks[mark] in parents:
-            old = repo[marks[mark]]
-            new = repo[node]
-            if old.descendant(new) and mark == cur:
-                marks[cur] = new.node()
-                update = True
-            if mark != cur:
-                del marks[mark]
+    if marks[cur] in parents:
+        old = repo[marks[cur]]
+        new = repo[node]
+        if old.descendant(new):
+            marks[cur] = new.node()
+            update = True
+
+    if deletedivergent(repo, parents, cur):
+        update = True
+
     if update:
         marks.write()
     return update