Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2018-10-30 21:44:40 +0300
committerJunio C Hamano <gitster@pobox.com>2018-10-31 06:48:59 +0300
commitff8978d533207f472b183223d88786b1053f1989 (patch)
treee50956d18ebd8814d9d29d274bf89cc41af25b4d /compat/winansi.c
parent4ede3d42dfb57f9a41ac96a1f216c62eb7566cc2 (diff)
mingw: fix isatty() after dup2()
Since a9b8a09c3c30 (mingw: replace isatty() hack, 2016-12-22), we handle isatty() by special-casing the stdin/stdout/stderr file descriptors, caching the return value. However, we missed the case where dup2() overrides the respective file descriptor. That poses a problem e.g. where the `show` builtin asks for a pager very early, the `setup_pager()` function sets the pager depending on the return value of `isatty()` and then redirects stdout. Subsequently, `cmd_log_init_finish()` calls `setup_pager()` *again*. What should happen now is that `isatty()` reports that stdout is *not* a TTY and consequently stdout should be left alone. Let's override dup2() to handle this appropriately. This fixes https://github.com/git-for-windows/git/issues/1077 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/winansi.c')
-rw-r--r--compat/winansi.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/compat/winansi.c b/compat/winansi.c
index a11a0f16d2..f4f08237f9 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -474,6 +474,18 @@ static void die_lasterr(const char *fmt, ...)
va_end(params);
}
+#undef dup2
+int winansi_dup2(int oldfd, int newfd)
+{
+ int ret = dup2(oldfd, newfd);
+
+ if (!ret && newfd >= 0 && newfd <= 2)
+ fd_is_interactive[newfd] = oldfd < 0 || oldfd > 2 ?
+ 0 : fd_is_interactive[oldfd];
+
+ return ret;
+}
+
static HANDLE duplicate_handle(HANDLE hnd)
{
HANDLE hresult, hproc = GetCurrentProcess();