Patchwork [6,of,7] color: move triggering of the initialisation logic in core

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 25, 2017, 1:11 p.m.
Message ID <0deb181adc74dea75b10.1488028298@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18785/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 25, 2017, 1:11 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487697612 -3600
#      Tue Feb 21 18:20:12 2017 +0100
# Node ID 0deb181adc74dea75b109ebdf38fb73f5f20c724
# Parent  25fd71d9347a8c82adf2a991dab0b48ff35282f6
# EXP-Topic color
color: move triggering of the initialisation logic in core

We now run the color initialisation as part of the standard dispatch. This is
opening the way for multiple cleanups since we now have access to the multiple 'ui'
object and we'll be able to see difference between global and local config. This
cleanup will arrive in later changesets.

As a side effect, the '--color' flag is now working without the extension.

Since we now properly initialize color for each ui idependently, we get a
warning message twice.
Yuya Nishihara - Feb. 27, 2017, 2:45 p.m.
On Sat, 25 Feb 2017 14:11:38 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1487697612 -3600
> #      Tue Feb 21 18:20:12 2017 +0100
> # Node ID 0deb181adc74dea75b109ebdf38fb73f5f20c724
> # Parent  25fd71d9347a8c82adf2a991dab0b48ff35282f6
> # EXP-Topic color
> color: move triggering of the initialisation logic in core
> 
> We now run the color initialisation as part of the standard dispatch. This is
> opening the way for multiple cleanups since we now have access to the multiple 'ui'
> object and we'll be able to see difference between global and local config. This
> cleanup will arrive in later changesets.
> 
> As a side effect, the '--color' flag is now working without the extension.
> 
> Since we now properly initialize color for each ui idependently, we get a
> warning message twice.

Doubled warnings are a bit unfortunate, but that wouldn't be easily avoidable
if we're going to handle per-ui differences correctly.
Pierre-Yves David - Feb. 27, 2017, 2:52 p.m.
On 02/27/2017 03:45 PM, Yuya Nishihara wrote:
> On Sat, 25 Feb 2017 14:11:38 +0100, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
>> # Date 1487697612 -3600
>> #      Tue Feb 21 18:20:12 2017 +0100
>> # Node ID 0deb181adc74dea75b109ebdf38fb73f5f20c724
>> # Parent  25fd71d9347a8c82adf2a991dab0b48ff35282f6
>> # EXP-Topic color
>> color: move triggering of the initialisation logic in core
>>
>> We now run the color initialisation as part of the standard dispatch. This is
>> opening the way for multiple cleanups since we now have access to the multiple 'ui'
>> object and we'll be able to see difference between global and local config. This
>> cleanup will arrive in later changesets.
>>
>> As a side effect, the '--color' flag is now working without the extension.
>>
>> Since we now properly initialize color for each ui idependently, we get a
>> warning message twice.
>
> Doubled warnings are a bit unfortunate, but that wouldn't be easily avoidable
> if we're going to handle per-ui differences correctly.

On way to fix it would be to check which group of 'key, value, source' 
have ben already warned about. However I would rather deal with this 
later as the main color code is complicated enough to migrated by itself.

Cheers,

Patch

diff -r 25fd71d9347a -r 0deb181adc74 hgext/color.py
--- a/hgext/color.py	Tue Feb 21 18:09:21 2017 +0100
+++ b/hgext/color.py	Tue Feb 21 18:20:12 2017 +0100
@@ -175,9 +175,6 @@  from mercurial import (
     cmdutil,
     color,
     commands,
-    dispatch,
-    extensions,
-    ui as uimod,
 )
 
 cmdtable = {}
@@ -188,15 +185,6 @@  command = cmdutil.command(cmdtable)
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def uisetup(ui):
-    def colorcmd(orig, ui_, opts, cmd, cmdfunc):
-        mode = color._modesetup(ui_, opts['color'])
-        uimod.ui._colormode = mode
-        if mode and mode != 'debug':
-            color.configstyles(ui_)
-        return orig(ui_, opts, cmd, cmdfunc)
-    extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
-
 def extsetup(ui):
     # change default color config
     for idx, entry in enumerate(commands.globalopts):
diff -r 25fd71d9347a -r 0deb181adc74 mercurial/color.py
--- a/mercurial/color.py	Tue Feb 21 18:09:21 2017 +0100
+++ b/mercurial/color.py	Tue Feb 21 18:20:12 2017 +0100
@@ -161,6 +161,17 @@  def _terminfosetup(ui, mode):
               "ECMA-48 color\n"))
         _terminfo_params.clear()
 
+def setup(ui, coloropts):
+    """configure color on a ui
+
+    The 'coloropts' argument is the value of the '--color' command line
+    argument. That function both set the colormode for the ui object and read
+    the configuration looking for custom colors and effect definitions."""
+    mode = _modesetup(ui, coloropts)
+    ui.__class__._colormode = mode
+    if mode and mode != 'debug':
+        configstyles(ui)
+
 def _modesetup(ui, coloropt):
     if ui.plain():
         return None
diff -r 25fd71d9347a -r 0deb181adc74 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Tue Feb 21 18:09:21 2017 +0100
+++ b/mercurial/dispatch.py	Tue Feb 21 18:20:12 2017 +0100
@@ -764,6 +764,10 @@  def _dispatch(req):
             for ui_ in uis:
                 ui_.insecureconnections = True
 
+        # setup color handling
+        for ui_ in uis:
+            color.setup(ui_, options['color'])
+
         if options['version']:
             return commands.version_(ui)
         if options['help']:
diff -r 25fd71d9347a -r 0deb181adc74 tests/test-status-color.t
--- a/tests/test-status-color.t	Tue Feb 21 18:09:21 2017 +0100
+++ b/tests/test-status-color.t	Tue Feb 21 18:20:12 2017 +0100
@@ -295,6 +295,7 @@  test unknown color
 
   $ hg --config color.status.modified=periwinkle status --color=always
   ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
+  ignoring unknown color/effect 'periwinkle' (configured in color.status.modified)
   M modified
   \x1b[0;32;1mA \x1b[0m\x1b[0;32;1madded\x1b[0m (esc)
   \x1b[0;32;1mA \x1b[0m\x1b[0;32;1mcopied\x1b[0m (esc)