summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-11-01 17:10:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-02 02:19:43 (GMT)
commit1a172e4ac1719a068c76384bd077ee65d915ebea (patch)
tree2b932386d50d83e9861f00a7a73059000eea54f9 /compat/mingw.c
parent3f944424ac899fb6705e7463d937c5ed581da207 (diff)
downloadgit-1a172e4ac1719a068c76384bd077ee65d915ebea.zip
git-1a172e4ac1719a068c76384bd077ee65d915ebea.tar.gz
git-1a172e4ac1719a068c76384bd077ee65d915ebea.tar.bz2
mingw: optionally redirect stderr/stdout via the same handle
The "2>&1" notation in Powershell and in Unix shells implies that stderr is redirected to the same handle into which stdout is already written. Let's use this special value to allow the same trick with GIT_REDIRECT_STDERR and GIT_REDIRECT_STDOUT: if the former's value is `2>&1`, then stderr will simply be written to the same handle as stdout. The functionality was suggested by Jeff Hostetler. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 6c6c779..2d44d21 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2160,6 +2160,21 @@ static void maybe_redirect_std_handle(const wchar_t *key, DWORD std_id, int fd,
CloseHandle(handle);
return;
}
+ if (std_id == STD_ERROR_HANDLE && !wcscmp(buf, L"2>&1")) {
+ handle = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (handle == INVALID_HANDLE_VALUE) {
+ close(fd);
+ handle = GetStdHandle(std_id);
+ if (handle != INVALID_HANDLE_VALUE)
+ CloseHandle(handle);
+ } else {
+ int new_fd = _open_osfhandle((intptr_t)handle, O_BINARY);
+ SetStdHandle(std_id, handle);
+ dup2(new_fd, fd);
+ /* do *not* close the new_fd: that would close stdout */
+ }
+ return;
+ }
handle = CreateFileW(buf, desired_access, 0, NULL, create_flag,
flags, NULL);
if (handle != INVALID_HANDLE_VALUE) {