changeset 100:7d0617e584ff

[states] fix strip but one thing still stay wrong (see test test-state-strip.t)
author Alain Leufroy <alain.leufroy@logilab.fr>
date Wed, 28 Sep 2011 12:35:55 +0200
parents 67a3aa020d91
children 21dbec91e775
files hgext/states.py tests/test-state-strip.t
diffstat 2 files changed, 140 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/states.py	Tue Sep 27 11:25:13 2011 +0200
+++ b/hgext/states.py	Wed Sep 28 12:35:55 2011 +0200
@@ -1038,35 +1038,28 @@
 
     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:
+        tostrip = set(map(cl.node, revstostrip))
+        # compute the potentially new created states bondaries which are any
+        # parent of the stripped node that are not stripped (may not be heads)
+        newbondaries = set(par for nod in tostrip for par in cl.parents(nod)
+                           if par not in tostrip)
+        # save the current states of newbondaries in a chache as repo.nodestate
+        # must work along the loop. We will use the next loop to add them.
+        statesheads={}
+        for nd in newbondaries:
             state = repo.nodestate(nd)
-            if not state.trackheads:
-                continue
-            statesheads.setdefault(state, set([])).add(nd)
+            if state.trackheads:
+                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 ?
-
+            if state.trackheads:
+                heads = set(heads) - tostrip | statesheads.get(state, set([]))
+                repo._statesheads[state] = list(heads)
+        _writestateshead(repo)
 
         return ostrip(ui, repo, node, backup)
+
     mercurial.repair.strip = strip
--- a/tests/test-state-strip.t	Tue Sep 27 11:25:13 2011 +0200
+++ b/tests/test-state-strip.t	Wed Sep 28 12:35:55 2011 +0200
@@ -121,6 +121,83 @@
   $ hg log --template "{rev} {node}\n" -r 'readyheads()'
   2 a00ba83de58390cbbdae1fc580df0bb0db2e8e88
 
+More complecated case: a merging changeset inheritate a ready state of one of
+its child and have another child in draft. And We strip the ready child
+  $ 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 ci -m 3
+  $ mkcommit 4
+  $ hg up 3
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit 5
+  created new head
+  $ mkcommit 6
+  $ hg ready 6
+  $ hglog
+  @  6 ready bfd1096b3dd69e57c184e9f43646a9b7e0dd5927
+  |
+  o  5 ready 8195da2a3c382a4acd7ce796b4bc74092f1875eb
+  |
+  | o  4 draft 6aaadc67da669af964adabe681c0a78f46b7ce58
+  |/
+  o    3 ready e7cd12398be70c568cefab9b4ad86a8a2a728a09
+  |\
+  | o  2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88
+  | |
+  o |  1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77
+  |/
+  o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
+  
+  $ hg strip -n 3
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ hglog
+  o  2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88
+  |
+  | @  1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77
+  |/
+  o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
+  
+Quitelly the same as before but we strip before the merging node, from another
+branch than the ready changeset, so this changeset is not a parent of the
+the explicitly stripped node.
+  $ 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 published 3
+  $ hg ready 4
+  $ hglog
+  @  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, 3 files removed, 0 files unresolved
+  $ hglog
+  o  2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88
+  |
+  | @  1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77
+  |/
+  o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
+  
+
 pathologic case
   $ hg up 1
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -162,4 +239,50 @@
   |/
   o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
   
-#  
+pathologic case
+  $ 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 ci -m 3
+  $ hg up 2
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit 4
+  created new head
+  $ hg merge 3
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m 5
+  $ hg up 4
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit 6
+  created new head
+  $ hg ready 4
+  $ hglog
+  @  6 draft 036d507f2b771a3b7cc88580c93d5037bf4bf1bf
+  |
+  | o  5 draft 19788060dab104e9385a14c4be2fc5678b9433f0
+  |/|
+  o |  4 ready 0fc8455e844047eab375a1f51816f697551e34cf
+  | |
+  | o  3 draft e7cd12398be70c568cefab9b4ad86a8a2a728a09
+  |/|
+  o |  2 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88
+  | |
+  | o  1 published e8342c9a2ed18fb27f9fdfc48a3105d164a06e77
+  |/
+  o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
+  
+  $ hg strip -n 1
+  $ hglog
+  @  3 draft 036d507f2b771a3b7cc88580c93d5037bf4bf1bf
+  |
+  o  2 ready 0fc8455e844047eab375a1f51816f697551e34cf
+  |
+  o  1 ready a00ba83de58390cbbdae1fc580df0bb0db2e8e88
+  |
+  o  0 published 06254b90631198c9b9e426be9886af92fedc9a2d
+  
+  $ hg log --template '{rev} {state} {node}\n' -r 'readyheads()'
+  2 ready 0fc8455e844047eab375a1f51816f697551e34cf