mingw: really handle SIGINT
Previously, we did not install any handler for Ctrl+C, but now we really want to because the MSYS2 runtime learned the trick to call the ConsoleCtrlHandler when Ctrl+C was pressed. With this, hitting Ctrl+C while `git log` is running will only terminate the Git process, but not the pager. This finally matches the behavior on Linux and on macOS. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 4, 2026 at 16:24 UTC
363f1d8b3a9c90f13ca6fd9ab0dc47e483e3cc9c
1 file changed
+9
compat/mingw.c
+9
@@ -3623,7 +3623,14 @@ static void adjust_symlink_flags(void)
3623
symlink_file_flags |= 2;
3624
symlink_directory_flags |= 2;
3625
}
3626
+}
3627
3628
+static BOOL WINAPI handle_ctrl_c(DWORD ctrl_type)
3629
+{
3630
+ if (ctrl_type != CTRL_C_EVENT)
3631
+ return FALSE; /* we did not handle this */
3632
+ mingw_raise(SIGINT);
3633
+ return TRUE; /* we did handle this */
3634
}
3635
3636
#ifdef _MSC_VER
@@ -3660,6 +3667,8 @@ int wmain(int argc, const wchar_t **wargv)
3667
#endif
3668
#endif
3669
3670
+ SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3671
+
3672
maybe_redirect_std_handles();
3673
adjust_symlink_flags();
3674