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

Re: [PATCH 2/2] mingw: replace isatty() hack

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 21, 2016, 18:45 UTC
Message-ID
<xmqqpokli0jh.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<18174f0a7fbb4a0ccd8ca8380e00161826166a32.1482342791.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 10 quoted lines
> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> For over a year, Git for Windows has carried a patch that detects the
> MSYS2 pseudo ttys used by Git for Windows' default Git Bash (i.e. a
> terminal that is not backed by a Win32 Console).
>
> This patch accesses internals that of a previous MSVC runtime that is no
> longer valid in newer versions, therefore we needed a replacement for
> that hack in order to be able to compile Git using recent Microsoft
> Visual C++.

Sorry, but I cannot parse the early part of the first sentence of the second paragraph before the comma; I am especially having trouble around the first "that".

Show 6 quoted lines
> This patch back-ports that patch and makes even the MINGW (i.e.
> GCC-compiled) Git use it.
>
> As a side effect (which was the reason for the back-port), this patch
> also fixes the previous misguided attempt to intercept isatty() so that
> it handles character devices (such as /dev/null) as Git expects it.

I had to read the above three times to understand which patches three instances of "This patch" and one instance of "that patch" refer to. I wish it were easier to read, but I think I got them all right [*1*] after re-reading, and the story made sense to me.

Show 12 quoted lines
> +static int fd_is_interactive[3] = { 0, 0, 0 };
> +#define FD_CONSOLE 0x1
> +#define FD_SWAPPED 0x2
> +#define FD_MSYS    0x4
>  
>  /*
>   ANSI codes used by git: m, K
> @@ -105,6 +108,9 @@ static int is_console(int fd)
>  	} else if (!GetConsoleScreenBufferInfo(hcon, &sbi))
>  		return 0;
>  
> +	if (fd >=0 && fd <= 2)
Style: if (fd >= 0 && fd <= 2)
> +/* Wrapper for isatty().  Most calls in the main git code
Style: /*
	* multi-line comment block begins with slash-asterisk
        * and ends with asterisk-slash without anything else on
	* the line.
	*/
Show 10 quoted lines
> + * call isatty(1 or 2) to see if the instance is interactive
> + * and should: be colored, show progress, paginate output.
> + * We lie and give results for what the descriptor WAS at
> + * startup (and ignore any pipe redirection we internally
> + * do).
> + */
> +#undef isatty
>  int winansi_isatty(int fd)
>  {
> +	if (fd >=0 && fd <= 2)
Style: if (fd >= 0 && fd <= 2)
> +		return fd_is_interactive[fd] != 0;
> +	return isatty(fd);
>  }
Thanks.
[Footnote]
*1* What I thought I understood in my own words:
    Git for Windows has carried a patch that depended on internals
    of MSVC runtime, but it does not work correctly with recent MSVC
    runtime.  A replacement was written originally for compiling
    with VC++.  The patch in this message is a backport of that
    replacement, and it also fixes the previous attempt to make
    isatty() work.
Previous: Johannes SchindelinNext: Johannes Sixt
Message 4 of 29 in “Really fix the isatty() problem on Windows”
  1. 0/2 Really fix the isatty() problem on WindowsJohannes Schindelin, Dec 21, 2016
  2. 1/2 mingw: adjust is_console() to work with stdinJohannes Schindelin, Dec 21, 2016
  3. 2/2 mingw: replace isatty() hackJohannes Schindelin, Dec 21, 2016
  4. Junio C HamanoDec 21, 2016
  5. Johannes SixtDec 21, 2016
  6. Junio C HamanoDec 21, 2016
  7. Johannes SixtDec 22, 2016
  8. Johannes SchindelinDec 22, 2016
  9. 0/3 Really fix the isatty() problem on WindowsJohannes Schindelin, Dec 22, 2016
  10. 2/3 mingw: fix colourization on Cygwin pseudo terminalsJohannes Schindelin, Dec 22, 2016
  11. 3/3 mingw: replace isatty() hackJohannes Schindelin, Dec 22, 2016
  12. Johannes SixtDec 22, 2016
  13. Johannes SchindelinDec 22, 2016
  14. Johannes SixtDec 22, 2016
  15. Johannes SchindelinDec 22, 2016
  16. 1/3 mingw: adjust is_console() to work with stdinJohannes Schindelin, Dec 22, 2016
  17. Beat BolliDec 22, 2016
  18. Junio C HamanoDec 22, 2016
  19. Johannes SchindelinDec 23, 2016
  20. Beat BolliDec 23, 2016
  21. Junio C HamanoDec 22, 2016
  22. Johannes SchindelinDec 22, 2016
  23. Junio C HamanoDec 22, 2016
  24. Junio C HamanoDec 22, 2016
  25. 0/3 Really fix the isatty() problem on WindowsJohannes Schindelin, Dec 22, 2016
  26. 1/3 mingw: adjust is_console() to work with stdinJohannes Schindelin, Dec 22, 2016
  27. 2/3 mingw: fix colourization on Cygwin pseudo terminalsJohannes Schindelin, Dec 22, 2016
  28. 3/3 mingw: replace isatty() hackJohannes Schindelin, Dec 22, 2016
  29. Johannes SchindelinJan 18, 2017

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.