Johannes Schindelin <johannes.schindelin@xxxxxx> writes: > From: Jeff Hostetler <jeffhost@xxxxxxxxxxxxx> > > 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". > 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. > +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. */ > + * 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.