Commits

Anonymous committed b6ab105

[states] change stateheads algo

now:
if highest state: repo heads
elif not fixed heads: *next lower state heads*
else: registered heads

before:
if higest state: repo heads
if if not fixed heads: next higher state heads
else: registered heads

  • Participants
  • Parent commits 0f98f25

Comments (0)

Files changed (1)

             else:
                 enabled.remove(state)
 
+        def lowerenabledstate(self, state):
+            try:
+                return max(st for st in self._enabledstates if st < state)
+            except ValueError:
+                return None
+
+        def higherenabledstate(self, state):
+            try:
+                return min(st for st in self._enabledstates if st > state)
+            except ValueError:
+                return None
+
         def stateheads(self, state):
-            """Return the set of head that define the state"""
+            """return the heads of the ``state``. If not found - state not
+            enabled or heads not fixed - return the heads of the previous
+            (lower) state.
+            """
             # look for a relevant state
-            while state.trackheads and state.next not in self._enabledstates:
-                state = state.next
-            # last state have no cached head.
-            if state.trackheads:
+            higher = self.higherenabledstate(state)
+            if higher is None:
+                return self.heads()
+            if state in self._statesheads:
                 return self._statesheads[state]
-            return self.heads()
+            lower = self.lowerenabledstate(state)
+            return self._statesheads[lower]
 
         @util.propertycache
         def _statesheads(self):