[states] add rebase support.
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Mon, 12 Sep 2011 23:47:06 +0200
changeset 63 f47a5f990eb2
parent 62 bd33e749dfcc
child 64 6a7dc5ca05b8
[states] add rebase support.
hgext/states.py
tests/test-published.t
--- a/hgext/states.py	Mon Sep 12 19:35:50 2011 +0200
+++ b/hgext/states.py	Mon Sep 12 23:47:06 2011 +0200
@@ -247,6 +247,13 @@
 
     - add ``<state>()`` directives that match all node in a state.
 
+Other extensions
+................
+
+:Rebase:     can't rewrite unpublished changeset.
+
+
+
 Implementation
 ==============
 
@@ -634,6 +641,22 @@
     h = repo.stateheads(st)
     return wireproto.encodelist(h) + "\n"
 
+# Other extension support
+#########################
+
+def wraprebasebuildstate(orig, repo, *args, **kwargs):
+   result = orig(repo, *args, **kwargs)
+   if result is not None:
+        revs = result[2]
+        base = repo.changelog.node(min(result[2]))
+        state = repo.nodestate(base)
+        if not state.properties & _MUTABLE:
+            raise util.Abort(_('can not rebase published changeset %s')
+                             % node.short(base),
+                             hint=_('see `hg help --extension states` for details'))
+   return result
+
+
 def uisetup(ui):
     """
     * patch stuff for the _NOSHARE property
@@ -656,6 +679,12 @@
     for state in STATES:
         if state.trackheads:
             revset.symbols[state.headssymbol] = state._revsetheads
+    try:
+        rebase = extensions.find('rebase')
+        if rebase:
+            extensions.wrapfunction(rebase, 'buildstate', wraprebasebuildstate)
+    except KeyError:
+        pass # rebase not found
 
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-published.t	Mon Sep 12 23:47:06 2011 +0200
@@ -0,0 +1,46 @@
+
+  $ cat >> $HGRCPATH <<EOF
+  > [web]
+  > push_ssl = false
+  > allow_push = *
+  > [extensions]
+  > hgext.rebase=
+  > EOF
+  $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH
+
+
+test you can't rebase published changeset
+
+  $ hg init local
+  $ cd local
+  $ echo "celestine" > babar
+  $ hg add babar
+  $ hg ci -m "add babar"
+  $ echo "la veille dame" > babar
+  $ hg ci -m "add dame"
+  $ hg log --template='{rev}:{node|short}: {state}\n'
+  1:710fe444b3b0: published
+  0:5caa672bac26: published
+  $ hg up 0 -q
+  $ echo "Rataxes" > rhino
+  $ hg add rhino
+  $ hg ci -m "add rhino"
+  created new head
+  $ hg up 1 -q
+  $ hg rebase
+  abort: can not rebase published changeset 710fe444b3b0
+  (see `hg help --extension states` for details)
+  [255]
+
+test you still can rebase other one
+
+  $ hg published 1 2
+  $ hg states draft
+  $ echo "flore" > babar
+  $ hg ci -m "add daughter"
+  $ hg rebase --dest 2
+  abort: can not rebase published changeset 710fe444b3b0
+  (see `hg help --extension states` for details)
+  [255]
+  $ hg rebase --dest 2 -s 3
+  saved backup bundle to $TESTTMP/local/.hg/strip-backup/b7f6698b7ad7-backup.hg