Skip to content
  • Karsten Blees's avatar
    Win32: reliably detect console pipe handles · 51822653
    Karsten Blees authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarJohannes Sixt <j6t@kdbg.org>
    Signed-off-by: default avatarKarsten Blees <blees@dcon.de>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    51822653