# HG changeset patch # User Alain Leufroy # Date 1316947605 -7200 # Node ID 8ad5c760c708340a944c65a2ee444668379a3bb8 # Parent e672cb1263cb17d23890c794c934751ebf58580f [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 diff -r e672cb1263cb -r 8ad5c760c708 doc/simple-tuto.t --- 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) diff -r e672cb1263cb -r 8ad5c760c708 hgext/states.py --- 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') )], '')} +cmdtable = {'states': (cmdstates, [ + ('', 'off', False, _('desactivate the state') ), + ('', 'clever', False, _('do not fix lower when activating the 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. diff -r e672cb1263cb -r 8ad5c760c708 tests/test-draft.t --- 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 diff -r e672cb1263cb -r 8ad5c760c708 tests/test-obsolete.t --- 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 diff -r e672cb1263cb -r 8ad5c760c708 tests/test-states-enable.t --- /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 < [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 + +