changeset 98:8ad5c760c708

[states] make enabling state saftier * Fix the lower state heads while enabling a state. * Add a --clever opiton that do not fix the lower heads (as earlier) * Add test for enable/disable state
author Alain Leufroy <alain.leufroy@logilab.fr>
date Sun, 25 Sep 2011 12:46:45 +0200
parents e672cb1263cb
children 67a3aa020d91
files doc/simple-tuto.t hgext/states.py tests/test-draft.t tests/test-obsolete.t tests/test-states-enable.t
diffstat 5 files changed, 214 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/doc/simple-tuto.t	Thu Sep 22 19:18:40 2011 +0200
+++ b/doc/simple-tuto.t	Sun Sep 25 12:46:45 2011 +0200
@@ -165,7 +165,7 @@
 
 You need to enable a mutable state in your repo the "ready" one
 
-  $ hg states ready # XXX --clever
+  $ hg states ready --clever
   $ hg ttlog
   d85de4546133: 'adding fruit' (ready)
   4d5dc8187023: 'adding condiment' (ready)
--- a/hgext/states.py	Thu Sep 22 19:18:40 2011 +0200
+++ b/hgext/states.py	Sun Sep 25 12:46:45 2011 +0200
@@ -151,8 +151,6 @@
  :on:      state enabled  for new repo
  :inherit: if present, inherit states of source on :hg:`clone`.
 
--  have a switch to select if changesets do change state on state activation.
-
 - display the number of changesets that change state when activating a state.
 
 
@@ -523,11 +521,14 @@
                                  state_name)
 
             else:
-                repo._enabledstates.add(st)
+                repo.enablestate(st, not opt.get('clever'))
         repo._writeenabledstates()
     return 0
 
-cmdtable = {'states': (cmdstates, [ ('', 'off', False, _('desactivate the state') )], '<state>')}
+cmdtable = {'states': (cmdstates, [
+    ('', 'off', False, _('desactivate the state') ),
+    ('', 'clever', False, _('do not fix lower when activating the state') )],
+    '<state>')}
 
 # automatic generation of command that set state
 def makecmd(state):
@@ -786,6 +787,13 @@
                         break
             return state
 
+        def enablestate(self, state, fix_lower=True):
+            if fix_lower:
+                # at least published which is always activated
+                lower = max(st for st in self._enabledstates if st < state)
+                self.setstate(lower, self.stateheads(state))
+            self._enabledstates.add(state)
+
         def disablestate(self, state):
             """Disable empty state.
             Raise error.Abort if the state is not empty.
--- a/tests/test-draft.t	Thu Sep 22 19:18:40 2011 +0200
+++ b/tests/test-draft.t	Sun Sep 25 12:46:45 2011 +0200
@@ -42,7 +42,7 @@
   0:5caa672bac26: published
 
 turn draft on (repo side)
-  $ hg states draft
+  $ hg states --clever draft
   $ hg log --template='{rev}:{node|short}: {state}\n'
   3:73585b17392a: draft
   2:3c8695235a32: draft
--- a/tests/test-obsolete.t	Thu Sep 22 19:18:40 2011 +0200
+++ b/tests/test-obsolete.t	Sun Sep 25 12:46:45 2011 +0200
@@ -206,7 +206,7 @@
   updating to branch default
   4 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
-  $ hg -R ../cloned states ready # XXX should be put in default config when state support it
+  $ hg -R ../cloned states --clever ready # XXX should be put in default config when state support it
   $ qlog -R ../cloned
   7
   - 909a0fb57e5d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-states-enable.t	Sun Sep 25 12:46:45 2011 +0200
@@ -0,0 +1,199 @@
+
+  $ cat >> $HGRCPATH <<EOF
+  > [web]
+  > push_ssl = false
+  > allow_push = *
+  > [extensions]
+  > EOF
+  $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH
+
+  $ mkcommit() {
+  >    echo "$1" > "$1"
+  >    hg add "$1"
+  >    hg ci -m "$1"
+  > }
+  $ alias hglog='hg log --template "{rev} {state}\n"'
+
+  $ hg init alpha
+  $ cd alpha
+  $ mkcommit 0
+  $ mkcommit 1
+
+
+enable draft: existing changesets stay as published and newer are draft
+  $ hg states draft
+  $ hg states
+  published
+  draft
+  $ hglog
+  1 published
+  0 published
+  $ mkcommit 2
+  $ hglog
+  2 draft
+  1 published
+  0 published
+
+enable ready: existing changset states are the same, newer are draft
+  $ hg states ready
+  $ hg states
+  published
+  ready
+  draft
+  $ hglog
+  2 draft
+  1 published
+  0 published
+  $ mkcommit 3
+  $ hglog
+  3 draft
+  2 draft
+  1 published
+  0 published
+
+
+publish all then enable states in other order
+  $ hg published tip
+  $ hg states --off ready draft
+  $ hglog
+  3 published
+  2 published
+  1 published
+  0 published
+
+enable ready: changesets stay as published and newer are ready
+  $ hg states ready
+  $ hglog
+  3 published
+  2 published
+  1 published
+  0 published
+  $ mkcommit 4
+  $ hglog
+  4 ready
+  3 published
+  2 published
+  1 published
+  0 published
+
+enable draft: changesets stay unchanged and newer are draft
+  $ hg states draft
+  $ hglog
+  4 ready
+  3 published
+  2 published
+  1 published
+  0 published
+  $ mkcommit 5
+  $ hglog
+  5 draft
+  4 ready
+  3 published
+  2 published
+  1 published
+  0 published
+
+disable ready
+  $ hg states --off ready
+  abort: could not disable non empty state ready
+  (You may want to use `hg published 'readyheads()'`)
+  [255]
+  $ hg publish 4
+  $ hg states --off ready
+  $ hg states
+  published
+  draft
+  $ hglog
+  5 draft
+  4 published
+  3 published
+  2 published
+  1 published
+  0 published
+  $ hg ready 4
+  abort: state ready is not activated
+  (try ``hg states ready`` before)
+  [255]
+
+disable draft
+  $ hg states --off draft
+  abort: could not disable non empty state draft
+  (You may want to use `hg published 'draftheads()'`)
+  [255]
+  $ hg publish tip
+  $ hg states --off draft
+  $ hg states
+  published
+  $ hglog
+  5 published
+  4 published
+  3 published
+  2 published
+  1 published
+  0 published
+  $ hg draft 5
+  abort: state draft is not activated
+  (try ``hg states draft`` before)
+  [255]
+
+disable published
+  $ hg states --off published
+  abort: could not disable published
+  [255]
+
+
+enable both draft and ready
+  $ hg states draft ready
+  $ hg states
+  published
+  ready
+  draft
+  $ hglog
+  5 published
+  4 published
+  3 published
+  2 published
+  1 published
+  0 published
+  $ mkcommit 6
+  $ hglog
+  6 draft
+  5 published
+  4 published
+  3 published
+  2 published
+  1 published
+  0 published
+
+disable both draft and ready
+  $ hg published tip
+  $ hg states --off draft ready
+  $ hg states
+  published
+
+clever enabling
+  $ hg states --clever ready
+  $ hglog
+  6 published
+  5 published
+  4 published
+  3 published
+  2 published
+  1 published
+  0 published
+
+  $ cd ..
+  $ hg init beta
+  $ cd beta
+  $ mkcommit 0
+  $ mkcommit 1
+  $ hg states --clever ready
+  $ hglog
+  1 ready
+  0 ready
+  $ hg states --clever draft
+  $ hglog
+  1 draft
+  0 draft
+
+