[PATCH 5 of 6] bookmarks: extract valid destination logic in a dedicated function

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Aug 24 10:14:59 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1343842849 -7200
# Node ID bb4f46cc1c046702a735ae9ab352302d48614f03
# Parent  79d63ffb7f1ff5daca6fcea74848b7ac729ee357
bookmarks: extract valid destination logic in a dedicated function

We usually update bookmarks only if the new location is descendant of the one.
We extract this logic in a function.This is the first step to allow more
complexe logic based using obsolescence in this decision.

The previous code were not wrappable. I do not expect anything outside mercurial
to break because of this change.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -207,11 +207,11 @@ def updatefromremote(ui, repo, remote, p
             if nr in repo:
                 cr = repo[nr]
                 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)
                 else:
                     # find a unique @ suffix
@@ -250,5 +250,9 @@ def diff(ui, repo, remote):
 
     if len(diff) <= 0:
         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()
diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -5,11 +5,11 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 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
     subset of nodes between repo and remote.
 
@@ -253,11 +253,11 @@ def checkheads(repo, remote, outgoing, r
     bookmarkedheads = set()
     for bm in localbookmarks:
         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.
     # If there are more heads after the push than before, a suitable
     # error message, depending on unsynced status, is displayed.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1987,11 +1987,11 @@ class localrepository(object):
             if k in self._bookmarks:
                 nr, nl = rb[k], hex(self._bookmarks[k])
                 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)
                         else:
                             self.ui.warn(_('updating bookmark %s'


More information about the Mercurial-devel mailing list