hgext/states.py
changeset 64 6a7dc5ca05b8
parent 63 f47a5f990eb2
child 65 7c8f992d567e
--- 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