{"thread":{"id":"30886","subject":"[PATCH/RFC] compat/terminal: support echoing on windows","startedAt":"2012-06-24T13:35:03Z","lastAt":"2012-06-27T21:08:11Z","messageCount":5,"participants":["Erik Faye-Lund","Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"194160","messageId":"1340544903-37016-1-git-send-email-kusmabite@gmail.com","threadId":"30886","inReplyTo":null,"subject":"[PATCH/RFC] compat/terminal: support echoing on windows","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-06-24T13:35:03Z","receivedAt":"2012-06-24T13:35:03Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Without /dev/tty support, git_terminal_prompt simply ignores the\n'echo'-parameter. On Windows we can do better by clevering up our\ngetpass-implementation a bit so it can conditionally echo.\n\nWhile we're at it, plug a small memory-leak by returning a pointer\nto a static strbuf instead of detaching it. This is the same thing\nthe /dev/tty-version of git_terminal_prompt does, and the callee\ndoesn't expect to have to free it's memory.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/mingw.c    | 15 ---------------\n compat/mingw.h    |  2 --\n compat/terminal.c | 20 ++++++++++++++++++++\n 3 files changed, 20 insertions(+), 17 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex afc892d..56ab74c 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1699,21 +1699,6 @@ int link(const char *oldpath, const char *newpath)\n \treturn 0;\n }\n \n-char *getpass(const char *prompt)\n-{\n-\tstruct strbuf buf = STRBUF_INIT;\n-\n-\tfputs(prompt, stderr);\n-\tfor (;;) {\n-\t\tchar c = _getch();\n-\t\tif (c == '\\r' || c == '\\n')\n-\t\t\tbreak;\n-\t\tstrbuf_addch(&buf, c);\n-\t}\n-\tfputs(\"\\n\", stderr);\n-\treturn strbuf_detach(&buf, NULL);\n-}\n-\n pid_t waitpid(pid_t pid, int *status, int options)\n {\n \tHANDLE h = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 61a6521..5e64a98 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -55,8 +55,6 @@ struct passwd {\n \tchar *pw_dir;\n };\n \n-extern char *getpass(const char *prompt);\n-\n typedef void (__cdecl *sig_handler_t)(int);\n struct sigaction {\n \tsig_handler_t sa_handler;\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex 6d16c8f..53c5166 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -71,6 +71,26 @@ char *git_terminal_prompt(const char *prompt, int echo)\n \treturn buf.buf;\n }\n \n+#elif defined(WIN32)\n+\n+char *git_terminal_prompt(const char *prompt, int echo)\n+{\n+\tstatic struct strbuf buf = STRBUF_INIT;\n+\n+\tfputs(prompt, stderr);\n+\tstrbuf_reset(&buf);\n+\tfor (;;) {\n+\t\tint c = _getch();\n+\t\tif (c == '\\n' || c == '\\r')\n+\t\t\tbreak;\n+\t\tif (echo)\n+\t\t\tputc(c, stderr);\n+\t\tstrbuf_addch(&buf, c);\n+\t}\n+\tputc('\\n', stderr);\n+\treturn buf.buf;\n+}\n+\n #else\n \n char *git_terminal_prompt(const char *prompt, int echo)\n-- \n1.7.11.1.27.gdae0dbb\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"194162","messageId":"alpine.DEB.1.00.1206240938050.16012@bonsai2","threadId":"30886","inReplyTo":"1340544903-37016-1-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH/RFC] compat/terminal: support echoing on windows","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2012-06-24T14:38:24Z","receivedAt":"2012-06-24T14:38:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 24 Jun 2012, Erik Faye-Lund wrote:\n\n> Without /dev/tty support, git_terminal_prompt simply ignores the\n> 'echo'-parameter. On Windows we can do better by clevering up our\n> getpass-implementation a bit so it can conditionally echo.\n> \n> While we're at it, plug a small memory-leak by returning a pointer\n> to a static strbuf instead of detaching it. This is the same thing\n> the /dev/tty-version of git_terminal_prompt does, and the callee\n> doesn't expect to have to free it's memory.\n\nLooks good, please apply!\n\nCiao,\nDscho\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"194164","messageId":"CABPQNSYLL_eHzo6LjNJWdO-WOfxbCUz2GPyg8p5Vvc0FmToPEg@mail.gmail.com","threadId":"30886","inReplyTo":"alpine.DEB.1.00.1206240938050.16012@bonsai2","subject":"Re: [PATCH/RFC] compat/terminal: support echoing on windows","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-06-24T15:38:24Z","receivedAt":"2012-06-24T15:38:24Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Sun, Jun 24, 2012 at 4:38 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Sun, 24 Jun 2012, Erik Faye-Lund wrote:\n>\n>> Without /dev/tty support, git_terminal_prompt simply ignores the\n>> 'echo'-parameter. On Windows we can do better by clevering up our\n>> getpass-implementation a bit so it can conditionally echo.\n>>\n>> While we're at it, plug a small memory-leak by returning a pointer\n>> to a static strbuf instead of detaching it. This is the same thing\n>> the /dev/tty-version of git_terminal_prompt does, and the callee\n>> doesn't expect to have to free it's memory.\n>\n> Looks good, please apply!\n\nDone.\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"194214","messageId":"CABPQNSYX9vZT0A4v5MMvC=yanNsLu7JMFoH1ZYy=vtaE7mwPpQ@mail.gmail.com","threadId":"30886","inReplyTo":"1340544903-37016-1-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH/RFC] compat/terminal: support echoing on windows","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2012-06-25T15:06:47Z","receivedAt":"2012-06-25T15:06:47Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Sun, Jun 24, 2012 at 3:35 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:\n> Without /dev/tty support, git_terminal_prompt simply ignores the\n> 'echo'-parameter. On Windows we can do better by clevering up our\n> getpass-implementation a bit so it can conditionally echo.\n>\n> While we're at it, plug a small memory-leak by returning a pointer\n> to a static strbuf instead of detaching it. This is the same thing\n> the /dev/tty-version of git_terminal_prompt does, and the callee\n> doesn't expect to have to free it's memory.\n>\n> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n> ---\n>  compat/mingw.c    | 15 ---------------\n>  compat/mingw.h    |  2 --\n>  compat/terminal.c | 20 ++++++++++++++++++++\n>  3 files changed, 20 insertions(+), 17 deletions(-)\n>\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index afc892d..56ab74c 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -1699,21 +1699,6 @@ int link(const char *oldpath, const char *newpath)\n>        return 0;\n>  }\n>\n> -char *getpass(const char *prompt)\n> -{\n> -       struct strbuf buf = STRBUF_INIT;\n> -\n> -       fputs(prompt, stderr);\n> -       for (;;) {\n> -               char c = _getch();\n> -               if (c == '\\r' || c == '\\n')\n> -                       break;\n> -               strbuf_addch(&buf, c);\n> -       }\n> -       fputs(\"\\n\", stderr);\n> -       return strbuf_detach(&buf, NULL);\n> -}\n> -\n>  pid_t waitpid(pid_t pid, int *status, int options)\n>  {\n>        HANDLE h = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,\n> diff --git a/compat/mingw.h b/compat/mingw.h\n> index 61a6521..5e64a98 100644\n> --- a/compat/mingw.h\n> +++ b/compat/mingw.h\n> @@ -55,8 +55,6 @@ struct passwd {\n>        char *pw_dir;\n>  };\n>\n> -extern char *getpass(const char *prompt);\n> -\n>  typedef void (__cdecl *sig_handler_t)(int);\n>  struct sigaction {\n>        sig_handler_t sa_handler;\n> diff --git a/compat/terminal.c b/compat/terminal.c\n> index 6d16c8f..53c5166 100644\n> --- a/compat/terminal.c\n> +++ b/compat/terminal.c\n> @@ -71,6 +71,26 @@ char *git_terminal_prompt(const char *prompt, int echo)\n>        return buf.buf;\n>  }\n>\n> +#elif defined(WIN32)\n> +\n> +char *git_terminal_prompt(const char *prompt, int echo)\n> +{\n> +       static struct strbuf buf = STRBUF_INIT;\n> +\n> +       fputs(prompt, stderr);\n> +       strbuf_reset(&buf);\n> +       for (;;) {\n> +               int c = _getch();\n> +               if (c == '\\n' || c == '\\r')\n> +                       break;\n> +               if (echo)\n> +                       putc(c, stderr);\n> +               strbuf_addch(&buf, c);\n> +       }\n> +       putc('\\n', stderr);\n> +       return buf.buf;\n> +}\n> +\n>  #else\n>\n>  char *git_terminal_prompt(const char *prompt, int echo)\n> --\n> 1.7.11.1.27.gdae0dbb\n>\n\nTurns out, this patch is incorrect; _getch is defined in conio.h,\nwhich is only included in compat/mingw.c and compat/msvc.c.\n\nThis patch on top fixes it:\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 56ab74c..d7d4aea 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1,6 +1,5 @@\n #include \"../git-compat-util.h\"\n #include \"win32.h\"\n-#include <conio.h>\n #include \"../strbuf.h\"\n #include \"../run-command.h\"\n\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex 71843d7..a3a4e0e 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -1,6 +1,5 @@\n #include \"../git-compat-util.h\"\n #include \"win32.h\"\n-#include <conio.h>\n #include \"../strbuf.h\"\n\n #include \"mingw.c\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 5bd9ad7..fa3e1a9 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -88,6 +88,7 @@\n #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */\n #include <winsock2.h>\n #include <windows.h>\n+#include <conio.h>\n #endif\n\n #include <unistd.h>\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"},{"id":"194379","messageId":"20120627210810.GC2292@sigill.intra.peff.net","threadId":"30886","inReplyTo":"1340544903-37016-1-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH/RFC] compat/terminal: support echoing on windows","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-06-27T21:08:11Z","receivedAt":"2012-06-27T21:08:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jun 24, 2012 at 03:35:03PM +0200, Erik Faye-Lund wrote:\n\n> Without /dev/tty support, git_terminal_prompt simply ignores the\n> 'echo'-parameter. On Windows we can do better by clevering up our\n> getpass-implementation a bit so it can conditionally echo.\n> \n> While we're at it, plug a small memory-leak by returning a pointer\n> to a static strbuf instead of detaching it. This is the same thing\n> the /dev/tty-version of git_terminal_prompt does, and the callee\n> doesn't expect to have to free it's memory.\n\nVery nice. I was hoping for something exactly like this when I wrote the\noriginal git_terminal_prompt patch.\n\n-Peff\n\n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n"}]}