Re: [PATCH] compat: add a getpass() compatibility function
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:16
Erik Faye-Lund [off-list ref] writes:
Do we really need two implementations? Wouldn't it be better to factor out the mingw-version to a separate source file, and then improve it?
Thanks for reminding.
Windows doesn't have /dev/tty, but the logic in this version handles that by using stdin/stderr instead. The signal-stuff has a comment that indicates it might not even be correct. tcgetattr/tcsetattr isn't supported on Windows, but it's not needed if we use getch (as the version in compat/mingw.c does). POSIX/curses getch respects the echo-setting, while Windows getch never echo.
I forgot to check how generic/reusable mingw version would look. As you said, it does feel a lot more attractive approach if it is trivial to add the "noecho" bit to it, tweak the tty-ness and deal with signals. I however suspect the result would end up on the borderline to be called "trivial", rough guestimate being 3-4 times as large as the 14-line mingw version. But it certainly feels that it is worth a try.