color: wrap qdiff/qseries after all extensions are loaded
authorBrodie Rao <me+hg@dackz.net>
Wed, 06 May 2009 16:27:50 -0400
changeset 8963 a4ceae3aa7be
parent 8962 4aade1a0115b
child 8964 119d1f664eae
child 8980 6d5dca8737b9
color: wrap qdiff/qseries after all extensions are loaded
hgext/color.py
--- a/hgext/color.py	Sun Jun 28 16:03:10 2009 -0400
+++ b/hgext/color.py	Wed May 06 16:27:50 2009 -0400
@@ -60,7 +60,7 @@
 
 import os, sys
 
-from mercurial import cmdutil, commands, extensions
+from mercurial import cmdutil, commands, extensions, error
 from mercurial.i18n import _
 
 # start and stop parameters for effects
@@ -220,18 +220,30 @@
                  'changed': ['white'],
                  'trailingwhitespace': ['bold', 'red_background']}
 
+_ui = None
+
 def uisetup(ui):
     '''Initialize the extension.'''
+    global _ui
+    _ui = ui
     _setupcmd(ui, 'diff', commands.table, colordiff, _diff_effects)
     _setupcmd(ui, 'incoming', commands.table, None, _diff_effects)
     _setupcmd(ui, 'log', commands.table, None, _diff_effects)
     _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
     _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
     _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
+
+def extsetup():
     try:
         mq = extensions.find('mq')
-        _setupcmd(ui, 'qdiff', mq.cmdtable, colordiff, _diff_effects)
-        _setupcmd(ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects)
+        try:
+            # If we are loaded after mq, we must wrap commands.table
+            _setupcmd(_ui, 'qdiff', commands.table, colordiff, _diff_effects)
+            _setupcmd(_ui, 'qseries', commands.table, colorqseries, _patch_effects)
+        except error.UnknownCommand:
+            # Otherwise we wrap mq.cmdtable
+            _setupcmd(_ui, 'qdiff', mq.cmdtable, colordiff, _diff_effects)
+            _setupcmd(_ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects)
     except KeyError:
         # The mq extension is not enabled
         pass