[PATCH V2] mq: defer command wrapping to extsetup (API)

Matt Harbison matt_harbison at yahoo.com
Mon Jun 11 21:48:52 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1339212479 14400
# Node ID 1014c89825093f798907f0fa8a04c9607a23271f
# Parent  2255950e1f7663a9faa6b57040cc5c0debe7d4dd
mq: defer command wrapping to extsetup (API)

mq wraps all commands that are not in commands.norepo, which is now performed in
this second phase of the extensions setup process.  This goes against the
current best practices on the wiki [1] as far as where command wrapping is
performed, but follows it regarding where global options are injected.

mq needs to be the first layer called when command dispatching in order to
consistently retarget to the patch repo, regardless of the load order of the
extensions.  This means being the last to wrap the command table.  Previously,
'hg <extdiff> --mq' would diff the main repo unless mq was enabled after
extdiff.

[1] http://mercurial.selenic.com/wiki/WritingExtensions

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3531,13 +3531,12 @@
     applied = set([repo[r.node].rev() for r in repo.mq.applied])
     return [r for r in subset if r in applied]
 
-def extsetup(ui):
-    revset.symbols['mq'] = revsetmq
-
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = [revsetmq]
 
-def uisetup(ui):
+def extsetup(ui):
+    # Ensure mq wrappers are called first, regardless of extension load order by
+    # NOT wrapping in uisetup() and instead deferring to init stage two here.
     mqopt = [('', 'mq', None, _("operate on patch repository"))]
 
     extensions.wrapcommand(commands.table, 'import', mqimport)
@@ -3562,6 +3561,7 @@
         if extmodule.__file__ != __file__:
             dotable(getattr(extmodule, 'cmdtable', {}))
 
+    revset.symbols['mq'] = revsetmq
 
 colortable = {'qguard.negative': 'red',
               'qguard.positive': 'yellow',


More information about the Mercurial-devel mailing list