Win32: reliably detect console pipe handles
commit51822653f58e6b9b6119f560ff864813fbde81ba
authorKarsten Blees <karsten.blees@gmail.com>
Fri, 13 Jun 2014 22:09:06 +0000 (14 00:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Jun 2014 17:56:19 +0000 (16 10:56 -0700)
treea4d932b93c0b699202688b84866fea4c5e1acaa9
parentfcd428f4a952a19d7553a9447fd4fa3c3584c6e6
Win32: reliably detect console pipe handles

As of "Win32: Thread-safe windows console output", child processes may
print to the console even if stdout has been redirected to a file. E.g.:

 git config tar.cat.command "cat"
 git archive -o test.cat HEAD

Detecting whether stdout / stderr point to our console pipe is currently
based on the assumption that OS HANDLE values are never reused. This is
apparently not true if stdout / stderr is replaced via dup2() (as in
builtin/archive.c:17).

Instead of comparing handle values, check if the file descriptor isatty()
backed by a pipe OS handle. This is only possible by swapping the handles
in MSVCRT's internal data structures, as we do in winansi_init().

Reported-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/winansi.c