[PATCH 1 of 2] obsolete: move validedest function in obsolete module

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Apr 12 11:55:21 CDT 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1365782993 -7200
#      Fri Apr 12 18:09:53 2013 +0200
# Node ID 5bd7702f8e9613a70b2dcf511aef85fd221eff78
# Parent  8c0a7eeda06d2773ec92b14527280db3e0167588
obsolete: move validedest function in obsolete module

Update related logic are going to use it too.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -231,11 +231,11 @@ def updatefromremote(ui, repo, remotemar
             if nr in repo:
                 cr = repo[nr]
                 cl = repo[nl]
                 if cl.rev() >= cr.rev():
                     continue
-                if validdest(repo, cl, cr):
+                if obsolete.validdest(repo, cl, cr):
                     localmarks[k] = cr.node()
                     changed = True
                     ui.status(_("updating bookmark %s\n") % k)
                 else:
                     if k == '@':
@@ -279,32 +279,5 @@ def diff(ui, dst, src):
     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"""
-    repo = repo.unfiltered()
-    if old == new:
-        # Old == new -> nothing to update.
-        return False
-    elif not old:
-        # old is nullrev, anything is valid.
-        # (new != nullrev has been excluded by the previous check)
-        return True
-    elif repo.obsstore:
-        # We only need this complicated logic if there is obsolescence
-        # XXX will probably deserve an optimised revset.
-        nm = repo.changelog.nodemap
-        validdests = set([old])
-        plen = -1
-        # compute the whole set of successors or descendants
-        while len(validdests) != plen:
-            plen = len(validdests)
-            succs = set(c.node() for c in validdests)
-            mutable = [c.node() for c in validdests if c.mutable()]
-            succs.update(obsolete.allsuccessors(repo.obsstore, mutable))
-            known = (n for n in succs if n in nm)
-            validdests = set(repo.set('%ln::', known))
-        return new in validdests
-    else:
-        return old.descendant(new)
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, bookmarks
+import util, setdiscovery, treediscovery, phases, obsolete
 import branchmap
 
 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.
@@ -255,11 +255,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 bookmarks.validdest(repo, rctx, lctx):
+            if obsolete.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
@@ -1933,11 +1933,11 @@ class localrepository(object):
             if k in unfi._bookmarks:
                 nr, nl = rb[k], hex(self._bookmarks[k])
                 if nr in unfi:
                     cr = unfi[nr]
                     cl = unfi[nl]
-                    if bookmarks.validdest(unfi, cr, cl):
+                    if obsolete.validdest(unfi, 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'
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -401,10 +401,41 @@ def allsuccessors(obsstore, nodes, ignor
             for suc in mark[1]:
                 if suc not in seen:
                     seen.add(suc)
                     remaining.add(suc)
 
+def validdest(repo, old, new):
+    """Is <new> a valid destination from the <old> one
+
+    Used by bookmark logic.
+    """
+    repo = repo.unfiltered()
+    if old == new:
+        # Old == new -> nothing to update.
+        return False
+    elif not old:
+        # old is nullrev, anything is valid.
+        # (new != nullrev has been excluded by the previous check)
+        return True
+    elif repo.obsstore:
+        # We only need this complicated logic if there is obsolescence
+        # XXX will probably deserve an optimised revset.
+        nm = repo.changelog.nodemap
+        validdests = set([old])
+        plen = -1
+        # compute the whole set of successors or descendants
+        while len(validdests) != plen:
+            plen = len(validdests)
+            succs = set(c.node() for c in validdests)
+            mutable = [c.node() for c in validdests if c.mutable()]
+            succs.update(allsuccessors(repo.obsstore, mutable))
+            known = (n for n in succs if n in nm)
+            validdests = set(repo.set('%ln::', known))
+        return new in validdests
+    else:
+        return old.descendant(new)
+
 def successorssets(repo, initialnode, cache=None):
     """Return all set of successors of initial nodes
 
     Successors set of changeset A are a group of revision that succeed A. It
     succeed A as a consistent whole, each revision being only partial


More information about the Mercurial-devel mailing list