changeset 112:eae9be0ee00e

adapt obsolete to phase.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Mon, 19 Dec 2011 14:05:25 +0100
parents ab4cef4fbd03
children 3bdabdbb4140
files hgext/obsolete.py tests/test-obsolete.t
diffstat 2 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/obsolete.py	Mon Dec 19 14:05:05 2011 +0100
+++ b/hgext/obsolete.py	Mon Dec 19 14:05:25 2011 +0100
@@ -101,7 +101,7 @@
     """is the changeset obsolete by other"""
     if ctx.node()is None:
         return False
-    return bool(ctx._repo.obsoletedby(ctx.node())) and ctx.state().mutable
+    return bool(ctx._repo.obsoletedby(ctx.node())) and ctx.phase()
 
 context.changectx.obsolete = obsolete
 
@@ -114,7 +114,7 @@
     # compute hidden (XXX should move elsewhere)
     if not getattr(ctx._repo.changelog, 'hiddeninit', False):
         shown = ['not obsolete()', '.', 'bookmark()', 'tagged()',
-                 'publishedheads()']
+                 'public()']
         basicquery = 'obsolete() - (::(%s))' % (' or '.join(shown))
         ctx._repo.changelog.hiddenrevs.update(
             scmutil.revrange(ctx._repo, [basicquery]))
@@ -126,11 +126,16 @@
 ### revset
 #############################
 
+def revsetpublic(repo, subset, x):
+    args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
+    # XXX slow stop using context
+    return [r for r in subset if repo._phaserev[r] == 0]
+
 def revsetobsolete(repo, subset, x):
     """filter obsolet entry"""
     args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
     # XXX slow stop using context
-    return [r for r in subset if r in repo._obsoleteset]
+    return [r for r in subset if r in repo._obsoleteset and repo._phaserev[r] > 0]
 
 ### Other Extension compat
 ############################
@@ -178,12 +183,9 @@
     return common, heads
 
 def extsetup(ui):
-    try:
-        rebase = extensions.find('states')
-    except KeyError:
-        raise error.Abort(_('obsolete extension require states extension.'))
 
     revset.symbols["obsolete"] = revsetobsolete
+    revset.symbols["public"] = revsetpublic
 
     extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout)
 
@@ -348,7 +350,7 @@
             self._obssubrels.setdefault(sub, set()).add(obj)
             self._obsobjrels.setdefault(obj, set()).add(sub)
             try:
-                if not self.nodestate(obj).mutable:
+                if self[obj].phase() == 0:
                     if sub is None:
                         self.ui.warn(
                             _("trying to kill immutable changeset %(obj)s\n")
@@ -463,13 +465,13 @@
                 entries.append(journalpath)
             return tuple(entries)
 
-        def rollback(self, dryrun=False):
+        def rollback(self, dryrun=False, **kwargs):
             """wrapped version of rollback that restore obsolete data"""
             wlock = lock = None
             try:
                 wlock = self.wlock()
                 lock = self.lock()
-                ret = orollback(dryrun)
+                ret = orollback(dryrun, **kwargs)
                 if not (ret or dryrun): #rollback did not failed
                     src = self.join('undo.obsolete-relations')
                     dst = self.join('obsolete-relations')
--- a/tests/test-obsolete.t	Mon Dec 19 14:05:05 2011 +0100
+++ b/tests/test-obsolete.t	Mon Dec 19 14:05:25 2011 +0100
@@ -2,9 +2,10 @@
   > [web]
   > push_ssl = false
   > allow_push = *
+  > [phases]
+  > publish=False
   > [extensions]
   > EOF
-  $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH
   $ echo "obsolete=$(echo $(dirname $TESTDIR))/hgext/obsolete.py" >> $HGRCPATH
   $ mkcommit() {
   >    echo "$1" > "$1"
@@ -15,9 +16,8 @@
   $ alias qlog="hg log --template='{rev}\n- {node|short}\n'"
   $ hg init local
   $ cd local
-  $ hg states ready # XXX should be put in default config when state support it
   $ mkcommit a # 0
-  $ hg published 0
+  $ hg pull -q . #hg published 0
   $ mkcommit b # 1
   $ mkcommit c # 2
   $ hg up 1
@@ -76,7 +76,6 @@
 Test communication of obsolete relation with a compatible client
 
   $ hg init ../other-new
-  $ hg -R ../other-new states ready # XXX should be put in default config when state support it
   $ hg push --traceback ../other-new
   pushing to ../other-new
   searching for changes
@@ -168,7 +167,6 @@
   $ hg init ../other-old
   > # XXX I don't like this but changeset get published otherwise
   > # remove it when we will get a --keep-state flag for push
-  $ hg -R ../other-old states ready
   $ echo '[extensions]'  > ../other-old/.hg/hgrc
   $ echo "obsolete=!$(echo $(dirname $TESTDIR))/obsolete.py" >> ../other-old/.hg/hgrc
   $ hg push ../other-old
@@ -199,14 +197,9 @@
   adding manifests
   adding file changes
   added 8 changesets with 8 changes to 8 files (+4 heads)
-  909a0fb57e5d try to obsolete immutable changeset 95de7fc6918d
-  95de7fc6918d try to obsolete immutable changeset a7a6f2b5d8a5
-  725c380fe99b try to obsolete immutable changeset 0d3f46688ccc
-  0d3f46688ccc try to obsolete immutable changeset 4538525df7e2
   updating to branch default
   4 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
-  $ hg -R ../cloned states --clever ready # XXX should be put in default config when state support it
   $ qlog -R ../cloned
   7
   - 909a0fb57e5d
@@ -248,7 +241,6 @@
   - 1f0dee641bb7
   $ hg -R ../other-new rollback
   repository tip rolled back to revision 7 (undo pull)
-  working directory now based on revision -1
   $ qlog -R ../other-new
   7
   - 909a0fb57e5d
@@ -261,7 +253,10 @@
   0
   - 1f0dee641bb7
 
-obsolete published changeset
+obsolete public changeset
+
+# move draft boundary from 0 to 1
+  $ sed -e 's/1f0dee641bb7258c56bd60e93edfa2405381c41e/7c3bad9141dcb46ff89abf5f61856facd56e476c/' -i'.back' .hg/store/phaseroots
 
   $ hg up null
   0 files updated, 0 files merged, 4 files removed, 0 files unresolved
@@ -290,7 +285,7 @@
   0
   - 1f0dee641bb7
 
-  $ hg debugobsolete null 9
+  $ hg debugobsolete null 9 #kill
   $ hg up null -q # to be not based on 9 anymore
   $ qlog
   8