[PATCH] color: fix crash in cmd.exe

Matt Harbison mharbison at attotech.com
Tue Mar 31 18:55:03 UTC 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1427826465 14400
#      Tue Mar 31 14:27:45 2015 -0400
# Node ID 3a14447d803cfd31f57bf48a7b80e5763a89f9d3
# Parent  c92f9acf447de31a6fe51ac664c26c42032117fd
color: fix crash in cmd.exe

When 'term' is None because it isn't in the environment, don't iterate over it.
Unfortunately, unsetting $TERM or exporting it as '' doesn't work in the tests,
so there's no way to simulate cmd.exe in the test suite.

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -234,8 +234,6 @@ def _modesetup(ui, coloropt):
         if os.name == 'nt':
             term = os.environ.get('TERM')
             # TERM won't be defined in a vanilla cmd.exe environment.
-            if not term:
-                realmode = 'win32'
 
             # UNIX-like environments on Windows such as Cygwin and MSYS will
             # set TERM. They appear to make a best effort attempt at setting it
@@ -244,7 +242,7 @@ def _modesetup(ui, coloropt):
             # gibberish, we error on the side of selecting "win32". However, if
             # w32effects is not defined, we almost certainly don't support
             # "win32", so don't even try.
-            if 'xterm' in term or not w32effects:
+            if (term and 'xterm' in term) or not w32effects:
                 realmode = 'ansi'
             else:
                 realmode = 'win32'


More information about the Mercurial-devel mailing list