Patchwork color: fix crash in cmd.exe

login
register
mail settings
Submitter Matt Harbison
Date March 31, 2015, 6:55 p.m.
Message ID <3a14447d803cfd31f57b.1427828103@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/8390/
State Accepted
Headers show

Comments

Matt Harbison - March 31, 2015, 6:55 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.
Matt Mackall - March 31, 2015, 7:04 p.m.
On Tue, 2015-03-31 at 14:55 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1427826465 14400
> #      Tue Mar 31 14:27:45 2015 -0400
> # Node ID 3a14447d803cfd31f57bf48a7b80e5763a89f9d3
> # Parent  c92f9acf447de31a6fe51ac664c26c42032117fd
> color: fix crash in cmd.exe

Queued for default (right?), thanks.
Matt Harbison - March 31, 2015, 7:10 p.m.
Matt Mackall <mpm@selenic.com> wrote on 03/31/2015 03:04:47 PM:

> From: Matt Mackall <mpm@selenic.com>
> To: Matt Harbison <mharbison@attotech.com>,
> Cc: mercurial-devel@selenic.com, matt_harbison@yahoo.com
> Date: 03/31/2015 03:05 PM
> Subject: Re: [PATCH] color: fix crash in cmd.exe
>
> On Tue, 2015-03-31 at 14:55 -0400, Matt Harbison wrote:
> > # HG changeset patch
> > # User Matt Harbison <matt_harbison@yahoo.com>
> > # Date 1427826465 14400
> > #      Tue Mar 31 14:27:45 2015 -0400
> > # Node ID 3a14447d803cfd31f57bf48a7b80e5763a89f9d3
> > # Parent  c92f9acf447de31a6fe51ac664c26c42032117fd
> > color: fix crash in cmd.exe
>
> Queued for default (right?), thanks.
>

Yep, sorry- it regressed in a78888d98606.  3.3.2 works fine.

Patch

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'