site

(Pierre-Yves David)
2011-06-06: introduce a ``laststatewithout`` method

introduce a ``laststatewithout`` method We use it to remove explicite reference to state in to module code. This allow more flexible dev for now.

diff --git a/states.py b/states.py
--- a/states.py
+++ b/states.py
@@ -37,9 +37,9 @@ from mercurial import wireproto
 
 class state(object):
 
-    def __init__(self, name, order=0, next=None):
+    def __init__(self, name, properties=0, next=None):
         self.name = name
-        self.order = order
+        self.properties = properties
         assert next is None or self < next
         self.next = next
 
@@ -57,7 +57,7 @@ class state(object):
         return self.next is not None
 
     def __cmp__(self, other):
-        return cmp(self.order, other.order)
+        return cmp(self.properties, other.properties)
 
     @util.propertycache
     def _revsetheads(self):
@@ -84,6 +84,13 @@ ST0 = state('published', next=ST1)
 
 STATES = (ST0, ST1, ST2)
 
+def laststatewithout(prop):
+    for state in STATES:
+        if not state.properties & prop:
+            candidate = state
+        else:
+            return candidate
+
 # util function
 #############################
 def noderange(repo, revsets):
@@ -141,7 +148,8 @@ def uisetup(ui):
     # Write protocols
     ####################
     def heads(repo, proto):
-        h = repo.stateheads(ST1)
+        st = laststatewithout(_NOSHARE)
+        h = repo.stateheads(st)
         return wireproto.encodelist(h) + "\n"
 
     def _reducehead(wirerepo, heads):
@@ -244,10 +252,11 @@ def reposetup(ui, repo):
 
         def _reducehead(self, candidates):
             selected = set()
+            st = laststatewithout(_NOSHARE)
             for candidate in candidates:
                 rev = self.changelog.rev(candidate)
                 ok = True
-                for h in self.stateheads(ST1):
+                for h in self.stateheads(st):
                     revh = self.changelog.rev(h)
                     if self.changelog.descendant(revh, rev):
                         ok = False
@@ -257,7 +266,8 @@ def reposetup(ui, repo):
             return sorted(selected)
 
         def cancopy(self):
-            return o_cancopy() and (self.stateheads(ST1) == self.heads())
+            st = laststatewithout(_NOSHARE)
+            return o_cancopy() and (self.stateheads(st) == self.heads())
 
     repo.__class__ = statefulrepo