changeset 24:20ac7fa3fd29

Move state activitation in a dedicated file repo-side The main issue with having state information is hgrc is that hgrc can be ignored for trust reason.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Fri, 01 Jul 2011 16:58:40 +0200
parents 423c62a146c7
children b372166d460d
files states.py tests/test-draft.t tests/test-ready.t
diffstat 3 files changed, 42 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/states.py	Fri Jul 01 16:00:19 2011 +0200
+++ b/states.py	Fri Jul 01 16:58:40 2011 +0200
@@ -82,10 +82,6 @@
         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)
@@ -131,6 +127,7 @@
         repo.setstate(state, [repo.changelog.node(rev) for rev in revs])
         return 0
     return cmdmoveheads
+
 for state in STATES:
     if state.trackheads:
         cmdmoveheads = makecmd(state)
@@ -218,7 +215,7 @@
 
         def stateheads(self, state):
             # look for a relevant state
-            while state.trackheads and not state.next.enabled(self.ui):
+            while state.trackheads and state.next not in self._enabledstates:
                 state = state.next
             # last state have no cached head.
             if state.trackheads:
@@ -300,10 +297,41 @@
                     selected.add(candidate)
             return sorted(selected)
 
+        ### enable // disable logic
+
+        @util.propertycache
+        def _enabledstates(self):
+            return self._readenabledstates()
+
+        def _readenabledstates(self):
+            states = set()
+            mapping = dict([(st.name, st) for st in STATES])
+            try:
+                f = self.opener('states/Enabled')
+                for line in f:
+                    st =  mapping.get(line.strip())
+                    if st is not None:
+                        states.add(st)
+            finally:
+                return states
+
+        def _writeenabledstates(self):
+            f = self.opener('states/Enabled', 'w', atomictemp=True)
+            try:
+                for st in self._enabledstates:
+                    f.write(st.name + '\n')
+                f.rename()
+            finally:
+                f.close()
+
+        ### local clone support
+
         def cancopy(self):
             st = laststatewithout(_NOSHARE)
             return ocancopy() and (self.stateheads(st) == self.heads())
 
+        ### pull // push support
+
         def pull(self, remote, *args, **kwargs):
             result = opull(remote, *args, **kwargs)
             remoteheads = self._pullimmutableheads(remote)
--- a/tests/test-draft.t	Fri Jul 01 16:00:19 2011 +0200
+++ b/tests/test-draft.t	Fri Jul 01 16:58:40 2011 +0200
@@ -42,10 +42,7 @@
   0:5caa672bac26: published
 
 turn draft on (repo side)
-  $ cat > .hg/hgrc << EOF
-  > [states]
-  > draft=yes
-  > EOF
+  $ echo draft > .hg/states/Enabled
   $ hg log --template='{rev}:{node|short}: {state}\n'
   3:73585b17392a: draft
   2:3c8695235a32: draft
@@ -77,7 +74,7 @@
   added 2 changesets with 2 changes to 1 files
 
 turn draft off again (repo side)
-  $ sed -i 's/^draft=.*$/draft=no/' .hg/hgrc
+  $ sed -i 's/draft//' .hg/states/Enabled
   $ hg log --template='{rev}:{node|short}: {state}\n'
   3:73585b17392a: published
   2:3c8695235a32: published
@@ -90,7 +87,7 @@
   3:73585b17392a
 
 turn draft on again (repo side)
-  $ sed -i 's/^draft=.*$/draft=yes/' .hg/hgrc
+  $ echo draft > .hg/states/Enabled
 
 test incoming and pull
 
@@ -166,7 +163,7 @@
 turn draft off again (repo side)
   $ cd ..
   $ "$TESTDIR/killdaemons.py"
-  $ sed -i 's/^draft=.*$/draft=off/' ./local/.hg/hgrc
+  $ sed -i 's/draft//' ./local/.hg/states/Enabled
   $ hg -R local serve -p $HGPORT -d --pid-file=local.pid
   $ cat local.pid >> "$DAEMON_PIDS"
   $ cd fromhttp2
@@ -188,7 +185,7 @@
   $ "$TESTDIR/killdaemons.py"
 
 turn draft on again (repo side)
-  $ sed -i 's/^draft=.*$/draft=on/' local/.hg/hgrc
+  $ echo draft > ./local/.hg/states/Enabled
   $ hg init httpto
   $ hg -R httpto serve -p $HGPORT -d --pid-file=remote.pid
   $ cat remote.pid >> "$DAEMON_PIDS"
--- a/tests/test-ready.t	Fri Jul 01 16:00:19 2011 +0200
+++ b/tests/test-ready.t	Fri Jul 01 16:58:40 2011 +0200
@@ -14,10 +14,8 @@
 
   $ hg init alpha
   $ cd alpha
-  $ cat > .hg/hgrc << EOF
-  > [states]
-  > ready=yes
-  > EOF
+  $ mkdir .hg/states
+  $ echo ready > .hg/states/Enabled
   $ mkcommit z
   $ mkcommit a
   $ mkcommit b
@@ -71,10 +69,8 @@
   $ cd ..
   $ hg init beta
   $ cd beta
-  $ cat > .hg/hgrc << EOF
-  > [states]
-  > ready=yes
-  > EOF
+  $ mkdir .hg/states
+  $ echo ready > .hg/states/Enabled
   $ hg pull ../alpha --update
   pulling from ../alpha
   requesting all changes