Merge branch 'js/mingw-isatty'
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:14:58 +0000 (13:14 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:14:58 +0000 (13:14 -0800)
An update to a topic that is already in 'master'.

* js/mingw-isatty:
mingw: follow-up to "replace isatty() hack"

1  2 
compat/winansi.c
diff --combined compat/winansi.c
index 3c9ed3cfe07c1f3b58f5400af861fb8ae44c3fdb,56658ec4f804630fa15791f78fb5df9a8fc0ea69..82b89ab13767a5e562d4f41826d98bce0d704e1c
@@@ -494,19 -494,16 +494,16 @@@ static HANDLE swap_osfhnd(int fd, HANDL
         * It is because of this implicit close() that we created the
         * copy of the original.
         *
-        * Note that the OS can recycle HANDLE (numbers) just like it
-        * recycles fd (numbers), so we must update the cached value
-        * of "console".  You can use GetFileType() to see that
-        * handle and _get_osfhandle(fd) may have the same number
-        * value, but they refer to different actual files now.
+        * Note that we need to update the cached console handle to the
+        * duplicated one because the dup2() call will implicitly close
+        * the original one.
         *
         * Note that dup2() when given target := {0,1,2} will also
         * call SetStdHandle(), so we don't need to worry about that.
         */
-       dup2(new_fd, fd);
        if (console == handle)
                console = duplicate;
-       handle = INVALID_HANDLE_VALUE;
+       dup2(new_fd, fd);
  
        /* Close the temp fd.  This explicitly closes "new_handle"
         * (because it has been associated with it).
@@@ -540,7 -537,7 +537,7 @@@ static void detect_msys_tty(int fd
                        buffer, sizeof(buffer) - 2, &result)))
                return;
        name = nameinfo->Name.Buffer;
 -      name[nameinfo->Name.Length] = 0;
 +      name[nameinfo->Name.Length / sizeof(*name)] = 0;
  
        /*
         * Check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX')