git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] winansi_isatty(): fix when Git is used from CMD

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 20, 2016, 16:50 UTC
Message-ID
<alpine.DEB.2.20.1612201732160.54750@virtualbox>
In-Reply-To
<ffc6a7a0-4ae4-b755-0b09-5bcd7114a2e6@kdbg.org>
Hi Hannes,
On Sun, 18 Dec 2016, Johannes Sixt wrote:
Show 22 quoted lines
> 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 <j6t@kdbg.org>
> ---
> I was able to test the idea earlier than anticipated and it does work
> for me.
Thank you.
Show 10 quoted lines
> 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

Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 21 in “Fix a long-standing isatty() problem on Windows”
  1. 0/1 Fix a long-standing isatty() problem on WindowsJohannes Schindelin, Dec 11, 2016
  2. 1/1 mingw: intercept isatty() to handle /dev/null as Git expects itJohannes Schindelin, Dec 11, 2016
  3. Johannes SixtDec 16, 2016
  4. Junio C HamanoDec 16, 2016
  5. Johannes SixtDec 16, 2016
  6. Junio C HamanoDec 16, 2016
  7. Johannes SchindelinDec 21, 2016
  8. winansi_isatty(): fix when Git is used from CMDJohannes Sixt, Dec 18, 2016
  9. Johannes SixtDec 18, 2016
  10. Johannes SixtDec 19, 2016
  11. Johannes SchindelinDec 21, 2016
  12. Johannes SchindelinDec 20, 2016
  13. Junio C HamanoDec 19, 2016
  14. Johannes SchindelinDec 20, 2016
  15. Junio C HamanoDec 20, 2016
  16. Johannes SchindelinDec 21, 2016
  17. Junio C HamanoDec 21, 2016
  18. Johannes SchindelinDec 22, 2016
  19. Junio C HamanoDec 11, 2016
  20. Johannes SchindelinDec 12, 2016
  21. Junio C HamanoDec 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.