Patchwork [2,of,7] color: cleanup 'debugcolor' logic

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 28, 2017, 7:25 p.m.
Message ID <a6afcb4e81ed425c633c.1488309942@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18841/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 28, 2017, 7:25 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1488048194 -3600
#      Sat Feb 25 19:43:14 2017 +0100
# Node ID a6afcb4e81ed425c633c206f121c5820ac91b0b0
# Parent  7e3d17f7acca8f1f1ff7d15864990201a528e1cd
# EXP-Topic color
color: cleanup 'debugcolor' logic

Now that style are carried by the 'ui' object, we no longer need complicated
logic to restore the original style. We just need to copy the 'ui' and work on
the copied version.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -357,26 +357,22 @@  def debugcolor(ui, repo, **opts):
         return _debugdisplaycolor(ui)
 
 def _debugdisplaycolor(ui):
-    oldstyle = ui._styles.copy()
-    try:
-        ui._styles.clear()
-        for effect in color._effects.keys():
-            ui._styles[effect] = effect
-        if ui._terminfoparams:
-            for k, v in ui.configitems('color'):
-                if k.startswith('color.'):
-                    ui._styles[k] = k[6:]
-                elif k.startswith('terminfo.'):
-                    ui._styles[k] = k[9:]
-        ui.write(_('available colors:\n'))
-        # sort label with a '_' after the other to group '_background' entry.
-        items = sorted(ui._styles.items(),
-                       key=lambda i: ('_' in i[0], i[0], i[1]))
-        for colorname, label in items:
-            ui.write(('%s\n') % colorname, label=label)
-    finally:
-        ui._styles.clear()
-        ui._styles.update(oldstyle)
+    ui = ui.copy()
+    ui._styles.clear()
+    for effect in color._effects.keys():
+        ui._styles[effect] = effect
+    if ui._terminfoparams:
+        for k, v in ui.configitems('color'):
+            if k.startswith('color.'):
+                ui._styles[k] = k[6:]
+            elif k.startswith('terminfo.'):
+                ui._styles[k] = k[9:]
+    ui.write(_('available colors:\n'))
+    # sort label with a '_' after the other to group '_background' entry.
+    items = sorted(ui._styles.items(),
+                   key=lambda i: ('_' in i[0], i[0], i[1]))
+    for colorname, label in items:
+        ui.write(('%s\n') % colorname, label=label)
 
 def _debugdisplaystyle(ui):
     ui.write(_('available style:\n'))