Smarter states heads.
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 06 Jun 2011 16:52:03 +0200
changeset 20 9983f240ac63
parent 19 8784a989a572
child 21 aa0870d093b8
Smarter states heads. We use the next relevant heads instead of repo one when asking for the head of a disabled state.
states.py
--- a/states.py	Mon Jun 06 15:30:43 2011 +0200
+++ b/states.py	Mon Jun 06 16:52:03 2011 +0200
@@ -78,6 +78,10 @@
         else:
             return 'heads'
 
+    def enabled(self, ui):
+        return ui.configbool('states', self.name, False)
+
+
 ST2 = state('draft', _NOSHARE | _MUTABLE)
 ST1 = state('ready', _MUTABLE, next=ST2)
 ST0 = state('published', next=ST1)
@@ -188,9 +192,12 @@
 
 
         def stateheads(self, state):
+            # look for a relevant state
+            while state.trackheads and not state.next.enabled(self.ui):
+                state = state.next
+            # last state have no cached head.
             if state.trackheads:
-                if self.ui.configbool('states', state.next.name, False):
-                    return self._statesheads[state]
+                return self._statesheads[state]
             return self.heads()
 
         @util.propertycache