[PATCH 5 of 6 V2] bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Sat Aug 25 18:54:05 CDT 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1345933736 -7200
# Node ID ab1306f88025dbf5285897d1b1261e58ad22d03a
# Parent 5bdfa3af04ef6f84de29d8c929d68b3e1e0ca579
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.
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -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()
diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -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.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1989,7 +1989,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)
More information about the Mercurial-devel
mailing list