mingw: follow-up to "replace isatty() hack"
The version of the "replace isatty() hack" that got merged a few weeks ago did not actually reflect the latest iteration of the patch series: v3 was sent out with these changes, as requested by the reviewer Johannes Sixt: - reworded the comment about "recycling handles" - moved the reassignment of the `console` variable before the dup2() call so that it is valid at all times - removed the "handle = INVALID_HANDLE_VALUE" assignment, as the local variable `handle` is not used afterwards anyway Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jan 18, 2017 at 13:14 UTC
1d3f065e0e4090a78640642cc1c1a3ce91d7852a
1 file changed
+4
-7
compat/winansi.c
+4
-7
@@ -494,19 +494,16 @@ static HANDLE swap_osfhnd(int fd, HANDLE new_handle)
494
* It is because of this implicit close() that we created the
495
* copy of the original.
496
*
497
- * Note that the OS can recycle HANDLE (numbers) just like it
498
- * recycles fd (numbers), so we must update the cached value
499
- * of "console". You can use GetFileType() to see that
500
- * handle and _get_osfhandle(fd) may have the same number
501
- * value, but they refer to different actual files now.
497
+ * Note that we need to update the cached console handle to the
498
+ * duplicated one because the dup2() call will implicitly close
499
+ * the original one.
500
*
501
* Note that dup2() when given target := {0,1,2} will also
502
* call SetStdHandle(), so we don't need to worry about that.
503
*/
506
- dup2(new_fd, fd);
504
if (console == handle)
505
console = duplicate;
509
- handle = INVALID_HANDLE_VALUE;
506
+ dup2(new_fd, fd);
507
508
/* Close the temp fd. This explicitly closes "new_handle"
509
* (because it has been associated with it).