Skip to content

Commit 1cbdbd7

Browse files
committed
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 <[email protected]>
1 parent 6ff703e commit 1cbdbd7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compat/mingw.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,6 +3294,14 @@ static void adjust_symlink_flags(void)
32943294

32953295
}
32963296

3297+
static BOOL handle_ctrl_c(DWORD ctrl_type)
3298+
{
3299+
if (ctrl_type != CTRL_C_EVENT)
3300+
return FALSE; /* we did not handle this */
3301+
mingw_raise(SIGINT);
3302+
return TRUE; /* we did handle this */
3303+
}
3304+
32973305
#if defined(_MSC_VER)
32983306

32993307
#ifdef _DEBUG
@@ -3332,6 +3340,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
33323340
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
33333341
#endif
33343342

3343+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3344+
33353345
fsync_object_files = 1;
33363346
maybe_redirect_std_handles();
33373347
adjust_symlink_flags();
@@ -3400,6 +3410,8 @@ void mingw_startup(void)
34003410
wchar_t **wenv, **wargv;
34013411
_startupinfo si;
34023412

3413+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3414+
34033415
fsync_object_files = 1;
34043416
maybe_redirect_std_handles();
34053417
adjust_symlink_flags();

0 commit comments

Comments
 (0)