Skip to content

Commit c08eca3

Browse files
kbleesdscho
authored andcommitted
git-wrapper: don't set the console input code page
Using different code pages for console input (SetConsoleCP()) and console output (SetConsoleOutputCP()) doesn't make much sense and may be hazardous for native Windows programs. Git uses UTF-8 internally, so it actually needs 'SetConsoleCP(CP_UTF8)' rather than 'SetConsoleCP(GetACP())'. However, ReadFile() / ReadConsoleA() are broken with CP_UTF8 (and thus any higher level APIs such as fgetc(), getchar() etc.). Unicode-aware console input would have to be implemented via mingw_* wrappers using ReadConsoleW(). As Git typically launches an editor for anything more complex than ASCII-only, yes/no-style questions, this is currently not a problem. Drop 'SetConsoleCP()' from the git-wrapper, so that input and output code pages stay in sync. Signed-off-by: Karsten Blees <[email protected]>
1 parent 0178d96 commit c08eca3

File tree

1 file changed

+0
-7
lines changed

1 file changed

+0
-7
lines changed

compat/win32/git-wrapper.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ int main(void)
321321
WCHAR exepath[MAX_PATH], exe[MAX_PATH];
322322
LPWSTR cmd = NULL, exep = exe, prefix_args = NULL, basename;
323323
LPWSTR working_directory = NULL;
324-
UINT codepage = 0;
325324

326325
/* Determine MSys2-based Git path. */
327326
swprintf(msystem_bin, sizeof(msystem_bin),
@@ -437,10 +436,6 @@ int main(void)
437436
}
438437
}
439438

440-
/* set the console to ANSI/GUI codepage */
441-
codepage = GetConsoleCP();
442-
SetConsoleCP(GetACP());
443-
444439
{
445440
STARTUPINFO si;
446441
PROCESS_INFORMATION pi;
@@ -499,7 +494,5 @@ int main(void)
499494

500495
free(cmd);
501496

502-
/* reset the console codepage */
503-
SetConsoleCP(codepage);
504497
ExitProcess(r);
505498
}

0 commit comments

Comments
 (0)