Commits

Pierre-Yves David  committed 20ac7fa

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.

  • Participants
  • Parent commits 423c62a
  • Branches default

Comments (0)

Files changed (3)

         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)
         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)
 
         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:
                     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)

File tests/test-draft.t

   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
   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
   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
 
 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
   $ "$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"

File tests/test-ready.t

 
   $ 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
   $ 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