Patchwork [1,of,2] color: set the ui class in reposetup, before a repo is created

login
register
mail settings
Submitter Simon Heimberg
Date April 18, 2013, 10:48 p.m.
Message ID <a3985f97aadad4c43b53.1366325289@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/1448/
State Accepted, archived
Headers show

Comments

Simon Heimberg - April 18, 2013, 10:48 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1366322004 -7200
# Node ID a3985f97aadad4c43b53377586a8f47274b4c2b3
# Parent  63a783d1ac852d60e60669b2f8551a9b26de2947
color: set the ui class in reposetup, before a repo is created

Previously only the class of repo.ui was set. The class was set in the wrapper
of dispatch._runcommand. But this is called after the repo is created. Only
the class of repo.ui is set because repo.baseui already exists and is not
accessible.
We now set the class in uisetup because this is called before repo creation.
This is also the place suggested in the wiki for modifying classes.
Bryan O'Sullivan - April 19, 2013, 8:42 p.m.
On Thu, Apr 18, 2013 at 3:48 PM, Simon Heimberg <simohe@besonet.ch> wrote:

> color: set the ui class in reposetup, before a repo is created
>

This causes Mercurial to crash if invoked with --color=no, and to always
enable color otherwise, even when writing to a pipe or a plain file.

Patch

diff -r 63a783d1ac85 -r a3985f97aada hgext/color.py
--- a/hgext/color.py	Don Apr 18 12:55:58 2013 -0700
+++ b/hgext/color.py	Don Apr 18 23:53:24 2013 +0200
@@ -381,13 +381,13 @@ 
 def uisetup(ui):
     if ui.plain():
         return
+    if not issubclass(ui.__class__, colorui):
+        colorui.__bases__ = (ui.__class__,)
+        ui.__class__ = colorui
     def colorcmd(orig, ui_, opts, cmd, cmdfunc):
         mode = _modesetup(ui_, opts)
         if mode:
             colorui._colormode = mode
-            if not issubclass(ui_.__class__, colorui):
-                colorui.__bases__ = (ui_.__class__,)
-                ui_.__class__ = colorui
             extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)