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

Yuya Nishihara yuya at tcha.org
Thu Apr 26 12:34:21 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at 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)

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


More information about the Mercurial-devel mailing list