color: fix crash in cmd.exe
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 31 Mar 2015 14:27:45 -0400
changeset 24535 1818d4dca75c
parent 24534 1925769b4ff8
child 24538 24df92075200
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.
hgext/color.py
--- a/hgext/color.py	Wed Mar 18 21:44:25 2015 -0700
+++ b/hgext/color.py	Tue Mar 31 14:27:45 2015 -0400
@@ -234,8 +234,6 @@
         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 @@
             # 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'