Alain Leufroy avatar Alain Leufroy committed 8ad5c76

[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

Comments (0)

Files changed (5)

doc/simple-tuto.t

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

tests/test-draft.t

   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

tests/test-obsolete.t

   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

tests/test-states-enable.t

+
+  $ 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
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.