Skip to content

Commit

Permalink
mingw: really handle SIGINT
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho authored and Git for Windows Build Agent committed Oct 22, 2024
1 parent 894838c commit 0a8b6cc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -3886,7 +3886,14 @@ static void adjust_symlink_flags(void)
symlink_file_flags |= 2;
symlink_directory_flags |= 2;
}
}

static BOOL WINAPI handle_ctrl_c(DWORD ctrl_type)
{
if (ctrl_type != CTRL_C_EVENT)
return FALSE; /* we did not handle this */
mingw_raise(SIGINT);
return TRUE; /* we did handle this */
}

#ifdef _MSC_VER
Expand Down Expand Up @@ -3923,6 +3930,8 @@ int wmain(int argc, const wchar_t **wargv)
#endif
#endif

SetConsoleCtrlHandler(handle_ctrl_c, TRUE);

maybe_redirect_std_handles();
adjust_symlink_flags();
fsync_object_files = 1;
Expand Down

0 comments on commit 0a8b6cc

Please sign in to comment.