Mercurial > evolve
changeset 99:67a3aa020d91
[states] fix strip but a case still does not work (see test test-state-strip.t)
author | Alain Leufroy <alain.leufroy@logilab.fr> |
---|---|
date | Tue, 27 Sep 2011 11:25:13 +0200 |
parents | 8ad5c760c708 |
children | 7d0617e584ff |
files | hgext/states.py tests/test-state-strip.t |
diffstat | 2 files changed, 203 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/states.py Sun Sep 25 12:46:45 2011 +0200 +++ b/hgext/states.py Tue Sep 27 11:25:13 2011 +0200 @@ -1032,3 +1032,41 @@ repo.__class__ = statefulrepo + import mercurial.repair + from operator import or_ + ostrip = mercurial.repair.strip + + def strip(ui, repo, node, backup="all"): + cl = repo.changelog + + striprev = cl.rev(node) + revstostrip = set(cl.descendants(striprev)) + revstostrip.add(striprev) + tostrip = set(cl.node(rev) for rev in revstostrip) # XXX stay in nodes? + + baserevstostrip = revstostrip - set(cl.descendants(*revstostrip)) + basetostrip = set(cl.node(rev) for rev in baserevstostrip) # XXX stay in nodes? + newstatesheads = reduce(or_, + (set(cl.parents(n)) for n in basetostrip), + set([])) + + statesheads={} # use this cache as repo.nodestate shall work + for nd in newstatesheads: + state = repo.nodestate(nd) + if not state.trackheads: + continue + statesheads.setdefault(state, set([])).add(nd) + + for state, heads in repo._statesheads.iteritems(): + if not state.trackheads: + continue + heads = set(heads) + headstostrip = tostrip & heads + heads.difference_update(headstostrip) + heads.update(statesheads.get(state, set([]))) + repo._statesheads[state] = list(heads) + _writestateshead(repo) # after ostrip ? + + + return ostrip(ui, repo, node, backup) + mercurial.repair.strip = strip
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-state-strip.t Tue Sep 27 11:25:13 2011 +0200 @@ -0,0 +1,165 @@ + + + $ cat >> $HGRCPATH <<EOF + > [web] + > push_ssl = false + > allow_push = * + > [extensions] + > hgext.mq= + > hgext.graphlog= + > EOF + $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH + + $ mkcommit() { + > echo "$1" > "$1" + > hg add "$1" + > hg ci -m "$1" + > } + $ alias hglog='hg glog --template "{rev} {state} {node}\n"' + + $ hg init alpha + $ cd alpha + $ hg states draft ready + $ mkcommit 0 + $ mkcommit 1 + $ hg up 0 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ mkcommit 2 + created new head + $ mkcommit 3 + $ mkcommit 4 + $ hg up 3 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ mkcommit 5 + created new head + $ hg up 1 + 1 files updated, 0 files merged, 3 files removed, 0 files unresolved + $ mkcommit 6 + $ hg published 6 + $ hg ready 4 + $ hglog + @ 6 published 2a653cad66937648173a936140f09a0e780afd76 + | + | o 5 draft ffe7eb8acef3efeceaa566b85a1ac419b0ecb856 + | | + | | o 4 ready 138777f75ddeb6ee0b527cfdb0eebbd1e0037bf6 + | |/ + | o 3 ready 0915e256b0ca7f81dace67bc6fd512bfd1bcab85 + | | + | o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | | + o | 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + + +We strip a published heads, so published heads 6 -> 1 + $ hg strip -n 6 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hglog + o 5 draft ffe7eb8acef3efeceaa566b85a1ac419b0ecb856 + | + | o 4 ready 138777f75ddeb6ee0b527cfdb0eebbd1e0037bf6 + |/ + o 3 ready 0915e256b0ca7f81dace67bc6fd512bfd1bcab85 + | + o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | + | @ 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + + +Back to the previous configuration. +Then strip accros branches and remove draft changesets completly, and cut in +the middle of ready changesets + $ hg up 1 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ mkcommit 6 + $ hg strip -n 3:6 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hglog + o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | + | @ 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + +Now merge 1 & 2 then strip merging changeset + $ hg up 1 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + $ hg commit -m Merge + $ hg strip -n 3 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hglog + o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | + | @ 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + +Do the same but with merge changeset as ready + $ hg up 1 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + $ hg commit -m Merge + $ hg ready 3 + $ hg strip -n 3 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hglog + o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | + | @ 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + + $ hg log --template "{rev} {node}\n" -r 'readyheads()' + 2 a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + +pathologic case + $ hg up 1 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ mkcommit 3 + $ hg up 2 + 1 files updated, 0 files merged, 2 files removed, 0 files unresolved + $ hg merge 3 + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + $ hg ci -m '4' + $ mkcommit 5 + $ hg up 3 + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved + $ mkcommit 6 + created new head + $ hg published 3 + $ hg ready 4 + $ hglog + @ 6 draft aeb74c71311d9305498bbf371746d095b80ff51f + | + | o 5 draft 0777a3135ec5396c57db4402c71ab8cba2a0ef7e + | | + | o 4 ready 667667458ecc8cf7763dee1ae172a5a9ebf115f3 + |/| + o | 3 published 03fc50a1c0074093104ff6c5357c486781742b64 + | | + | o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | | + o | 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + + $ hg strip -n 3 + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved + $ hglog + o 2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88 + | + | @ 1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77 + |/ + o 0 published 06254b90631198c9b9e426be9886af92fedc9a2d + +#