changeset 64:6a7dc5ca05b8

[states] add mq support
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 13 Sep 2011 00:45:42 +0200
parents f47a5f990eb2
children 7c8f992d567e
files hgext/states.py tests/test-published.t
diffstat 2 files changed, 45 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/states.py	Mon Sep 12 23:47:06 2011 +0200
+++ b/hgext/states.py	Tue Sep 13 00:45:42 2011 +0200
@@ -250,7 +250,8 @@
 Other extensions
 ................
 
-:Rebase:     can't rewrite unpublished changeset.
+:rebase:     can't rebase immutable changeset.
+:mq:         can't qimport immutable changeset.
 
 
 
@@ -656,6 +657,18 @@
                              hint=_('see `hg help --extension states` for details'))
    return result
 
+def wrapmqqimport(orig, queue, repo, *args, **kwargs):
+   if 'rev' in kwargs:
+       # we can take the min as non linear import wil break
+       base = min(scmutil.revrange(repo, kwargs['rev']))
+       basenode = repo.changelog.node(base)
+       state = repo.nodestate(basenode)
+       if not state.properties & _MUTABLE:
+           raise util.Abort(_('can not qimport published changeset %s')
+                            % node.short(basenode),
+                            hint=_('see `hg help --extension states` for details'))
+   return orig(queue, repo, *args, **kwargs)
+
 
 def uisetup(ui):
     """
@@ -679,12 +692,20 @@
     for state in STATES:
         if state.trackheads:
             revset.symbols[state.headssymbol] = state._revsetheads
+    # wrap rebase
     try:
         rebase = extensions.find('rebase')
         if rebase:
             extensions.wrapfunction(rebase, 'buildstate', wraprebasebuildstate)
     except KeyError:
         pass # rebase not found
+    # wrap mq
+    try:
+        mq = extensions.find('mq')
+        if mq:
+            extensions.wrapfunction(mq.queue, 'qimport', wrapmqqimport)
+    except KeyError:
+        pass # mq not found
 
 
 
--- a/tests/test-published.t	Mon Sep 12 23:47:06 2011 +0200
+++ b/tests/test-published.t	Tue Sep 13 00:45:42 2011 +0200
@@ -5,11 +5,12 @@
   > allow_push = *
   > [extensions]
   > hgext.rebase=
+  > hgext.mq=
   > EOF
   $ echo "states=$(echo $(dirname $TESTDIR))/hgext/states.py" >> $HGRCPATH
 
 
-test you can't rebase published changeset
+init stuff
 
   $ hg init local
   $ cd local
@@ -26,21 +27,33 @@
   $ hg add rhino
   $ hg ci -m "add rhino"
   created new head
+  $ hg published 1 2
   $ hg up 1 -q
-  $ hg rebase
+  $ hg states draft
+  $ echo "flore" > babar
+  $ hg ci -m "add daughter"
+
+test you can't qimport published changeset
+
+  $ hg qimport -r 1
+  abort: can not qimport published changeset 710fe444b3b0
+  (see `hg help --extension states` for details)
+  [255]
+
+but other are ok
+
+  $ hg qimport -r 3
+  $ hg qfinish -a
+
+test you can't rebase published changeset
+
+  $ hg rebase --dest 2 -b 1
   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
+