From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-5.5 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id AEB23203EA for ; Tue, 20 Dec 2016 16:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936180AbcLTQuV (ORCPT ); Tue, 20 Dec 2016 11:50:21 -0500 Received: from mout.gmx.net ([212.227.15.15]:64735 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934237AbcLTQuT (ORCPT ); Tue, 20 Dec 2016 11:50:19 -0500 Received: from virtualbox ([37.24.141.236]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lg0sd-1cvBOI2Ncx-00pbUw; Tue, 20 Dec 2016 17:50:05 +0100 Date: Tue, 20 Dec 2016 17:50:04 +0100 (CET) From: Johannes Schindelin X-X-Sender: virtualbox@virtualbox To: Johannes Sixt cc: Junio C Hamano , git@vger.kernel.org, Pranit Bauva Subject: Re: [PATCH] winansi_isatty(): fix when Git is used from CMD In-Reply-To: Message-ID: References: <42ddc270ea04e01e899cc479063e5d602e4a4448.1481454992.git.johannes.schindelin@gmx.de> <129f000c-49c1-0e75-26b3-c96e9b442443@kdbg.org> <5977e71d-da58-7cb0-bc69-343bb3a1341d@kdbg.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Provags-ID: V03:K0:MjjFW3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xv5Y9SyfO2tAxshj JV8tm5e Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi Hannes, On Sun, 18 Dec 2016, Johannes Sixt wrote: > The code in winansi.c emulates ANSI escape sequences when Git is > connected to the "real" windows console, CMD.exe. The details are > outline in eac14f8909d9 (Win32: Thread-safe windows console output, > 2012-01-14). Essentially, it plugs a pipe between C code and the actual > console output handle. > > This commit also added an override for isatty(), but it was made > unnecessary by fcd428f4a952 (Win32: fix broken pipe detection, > 2012-03-01). > > The new isatty() override implemented by cbb3f3c9b197 (mingw: intercept > isatty() to handle /dev/null as Git expects it, 2016-12-11) does not > take into account that _get_osfhandle() returns the handle visible by > the C code, which is the pipe. But it actually wants to investigate the > properties of the handle that is actually connected to the outside > world. Fortunately, there is already winansi_get_osfhandle(), which > returns exactly this handle. Use it. > > Signed-off-by: Johannes Sixt > --- > I was able to test the idea earlier than anticipated and it does work > for me. Thank you. > diff --git a/compat/winansi.c b/compat/winansi.c > index cb725fb02f..ba360be69b 100644 > --- a/compat/winansi.c > +++ b/compat/winansi.c > @@ -586,7 +586,7 @@ int winansi_isatty(int fd) > * > * https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx > */ > - HANDLE handle = (HANDLE)_get_osfhandle(fd); > + HANDLE handle = winansi_get_osfhandle(fd); That code works because winansi_get_osfhandle() is in winansi.c, where its call to isatty() is *not* redirected to winansi_isatty(). Good. My plan was actually to clean up the "magic" detect_msys_tty() code: it messes with internals of the MSVC runtime that are no longer the same in the Universal Runtime (UCRT), and hence we already had to come up with a different way to detect an MSYS2 pipe. My preference would be to merge that logic into winansi_isatty() and abandon the _pioinfo hack. Let's just clean up all of this in one go. Ciao, Dscho