introduce a ``laststatewithout`` method
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 06 Jun 2011 15:30:43 +0200
changeset 19 8784a989a572
parent 18 9ffe946febc0
child 20 9983f240ac63
introduce a ``laststatewithout`` method We use it to remove explicite reference to state in to module code. This allow more flexible dev for now.
states.py
--- a/states.py	Wed May 25 02:27:40 2011 +0200
+++ b/states.py	Mon Jun 06 15:30:43 2011 +0200
@@ -37,9 +37,9 @@
 
 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 @@
         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 @@
 
 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 @@
     # 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 _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 @@
             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