changeset 17550:fc530080013b

bookmarks: extract valid destination logic in a dedicated function We usually update bookmarks only if the new location is descendant of the old bookmarks location. We extract this logic into a function. This is the first step to allow more complex logic using obsolescence in this validation of the bookmark movement.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Sun, 26 Aug 2012 00:28:56 +0200
parents be0fcbb1c92f
children a7b3fdaf768d
files mercurial/bookmarks.py mercurial/discovery.py mercurial/localrepo.py
diffstat 3 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Sun Aug 26 00:27:44 2012 +0200
+++ b/mercurial/bookmarks.py	Sun Aug 26 00:28:56 2012 +0200
@@ -209,7 +209,7 @@
                 cl = repo[nl]
                 if cl.rev() >= cr.rev():
                     continue
-                if cr in cl.descendants():
+                if validdest(repo, cl, cr):
                     repo._bookmarks[k] = cr.node()
                     changed = True
                     ui.status(_("updating bookmark %s\n") % k)
@@ -252,3 +252,7 @@
         ui.status(_("no changed bookmarks found\n"))
         return 1
     return 0
+
+def validdest(repo, old, new):
+    """Is the new bookmark destination a valid update from the old one"""
+    return new in old.descendants()
--- a/mercurial/discovery.py	Sun Aug 26 00:27:44 2012 +0200
+++ b/mercurial/discovery.py	Sun Aug 26 00:28:56 2012 +0200
@@ -7,7 +7,7 @@
 
 from node import nullid, short
 from i18n import _
-import util, setdiscovery, treediscovery, phases, obsolete
+import util, setdiscovery, treediscovery, phases, obsolete, bookmarks
 
 def findcommonincoming(repo, remote, heads=None, force=False):
     """Return a tuple (common, anyincoming, heads) used to identify the common
@@ -255,7 +255,7 @@
         rnode = remotebookmarks.get(bm)
         if rnode and rnode in repo:
             lctx, rctx = repo[bm], repo[rnode]
-            if rctx == lctx.ancestor(rctx):
+            if bookmarks.validdest(repo, rctx, lctx):
                 bookmarkedheads.add(lctx.node())
 
     # 3. Check for new heads.
--- a/mercurial/localrepo.py	Sun Aug 26 00:27:44 2012 +0200
+++ b/mercurial/localrepo.py	Sun Aug 26 00:28:56 2012 +0200
@@ -1992,7 +1992,7 @@
                 if nr in self:
                     cr = self[nr]
                     cl = self[nl]
-                    if cl in cr.descendants():
+                    if bookmarks.validdest(self, cr, cl):
                         r = remote.pushkey('bookmarks', k, nr, nl)
                         if r:
                             self.ui.status(_("updating bookmark %s\n") % k)