Patchwork [STABLE] debugcolor: fix crash by empty styles (issue5856)

login
register
mail settings
Submitter Yuya Nishihara
Date April 26, 2018, 12:34 p.m.
Message ID <2098173ebe1bd9273e10.1524746061@mimosa>
Download mbox | patch
Permalink /patch/31237/
State Accepted
Headers show

Comments

Yuya Nishihara - April 26, 2018, 12:34 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1524745453 -32400
#      Thu Apr 26 21:24:13 2018 +0900
# Branch stable
# Node ID 2098173ebe1bd9273e10028fa446eb23b4ca1322
# Parent  7dffecb148aa77184b19c054e301345b3b51af1b
debugcolor: fix crash by empty styles (issue5856)
Augie Fackler - April 26, 2018, 5:17 p.m.
> On Apr 26, 2018, at 08:34, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1524745453 -32400
> #      Thu Apr 26 21:24:13 2018 +0900
> # Branch stable
> # Node ID 2098173ebe1bd9273e10028fa446eb23b4ca1322
> # Parent  7dffecb148aa77184b19c054e301345b3b51af1b
> debugcolor: fix crash by empty styles (issue5856)

queued, thanks

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -462,6 +462,8 @@  def _debugdisplaycolor(ui):
 
 def _debugdisplaystyle(ui):
     ui.write(_('available style:\n'))
+    if not ui._styles:
+        return
     width = max(len(s) for s in ui._styles)
     for label, effects in sorted(ui._styles.items()):
         ui.write('%s' % label, label=label)
diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -333,6 +333,19 @@  Test cache warming command
   .hg/cache/rbc-names-v1
   .hg/cache/branch2-served
 
+Test debugcolor
+
+#if no-windows
+  $ hg debugcolor --style --color always | egrep 'mode|style|log\.'
+  color mode: ansi
+  available style:
+  \x1b[0;33mlog.changeset\x1b[0m:                      \x1b[0;33myellow\x1b[0m (esc)
+#endif
+
+  $ hg debugcolor --style --color never
+  color mode: None
+  available style:
+
   $ cd ..
 
 Test internal debugstacktrace command