[PATCH 4 of 4] color: load 'colortable' from extension using an 'extraloader'

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Dec 21 11:23:19 EST 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1479489495 -3600
#      Fri Nov 18 18:18:15 2016 +0100
# Node ID ea3cd4faf533dcf3323cbb2a11468a30ea065af3
# Parent  764600c7f44086f0d6bbbaf31a668093999190ce
# EXP-Topic color
color: load 'colortable' from extension using an 'extraloader'

Now that we have the '_style' dictionary in core, we can use the clean and
standard 'extraloader' mechanism to load extension's 'colortable'.
color.loadcolortable

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -358,10 +358,6 @@ def render_effects(text, effects):
         stop = _effect_str('none')
     return ''.join([start, text, stop])
 
-def extstyles():
-    for name, ext in extensions.extensions():
-        color._styles.update(getattr(ext, 'colortable', {}))
-
 def valideffect(effect):
     'Determine if the effect is valid or not.'
     good = False
@@ -459,7 +455,6 @@ def uisetup(ui):
         mode = _modesetup(ui_, opts['color'])
         colorui._colormode = mode
         if mode and mode != 'debug':
-            extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
     def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -60,3 +60,6 @@ from __future__ import absolute_import
            'status.unknown': 'magenta bold underline',
            'tags.normal': 'green',
            'tags.local': 'black bold'}
+
+def loadcolortable(ui, extname, colortable):
+    _styles.update(colortable)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -25,6 +25,7 @@ from .i18n import _
 
 from . import (
     cmdutil,
+    color,
     commands,
     demandimport,
     encoding,
@@ -730,6 +731,7 @@ def _cmdattr(ui, cmd, func, attr):
 #   extraobj) arguments
 extraloaders = [
     ('cmdtable', commands, 'loadcmdtable'),
+    ('colortable', color, 'loadcolortable'),
     ('filesetpredicate', fileset, 'loadpredicate'),
     ('revsetpredicate', revset, 'loadpredicate'),
     ('templatefilter', templatefilters, 'loadfilter'),


More information about the Mercurial-devel mailing list