]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mingw: really handle SIGINT
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 4 Jun 2026 16:24:20 +0000 (16:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Jun 2026 13:39:57 +0000 (22:39 +0900)
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>
compat/mingw.c

index 44c63059cd69169941da5dbe571c765e941b6721..41e055f7de885e14d4d1af423e764353ea329f7e 100644 (file)
@@ -3623,7 +3623,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
@@ -3660,6 +3667,8 @@ int wmain(int argc, const wchar_t **wargv)
 #endif
 #endif
 
+       SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
+
        maybe_redirect_std_handles();
        adjust_symlink_flags();