{"thread":{"id":"18774","subject":"[PATCH] Add a simple getpass() for MinGW","startedAt":"2009-04-08T01:30:22Z","lastAt":"2009-04-10T18:03:07Z","messageCount":5,"participants":["Johannes Schindelin","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"110764","messageId":"7ba615a300fe2742e8d32f0313c6ee9a1a1aaed3.1239154140u.git.johannes.schindelin@gmx.de","threadId":"18774","inReplyTo":"cover.1239154140u.git.johannes.schindelin@gmx.de","subject":"[PATCH] Add a simple getpass() for MinGW","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-08T01:30:22Z","receivedAt":"2009-04-08T01:30:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"This should be replaced with a graphical getpass() at some stage.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI saw it coming that I had to do this.\n\n compat/mingw.c |   15 +++++++++++++++\n 1 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex d50186e..2ab5bbe 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1157,3 +1157,18 @@ int link(const char *oldpath, const char *newpath)\n \t}\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-- \n1.6.2.1.613.g25746\n"},{"id":"110773","messageId":"7vfxgjub7c.fsf@gitster.siamese.dyndns.org","threadId":"18774","inReplyTo":"7ba615a300fe2742e8d32f0313c6ee9a1a1aaed3.1239154140u.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] Add a simple getpass() for MinGW","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-08T02:32:39Z","receivedAt":"2009-04-08T02:32:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; should I take this directly or via Hannes's pull request?\n"},{"id":"110776","messageId":"alpine.DEB.1.00.0904080455220.10279@pacific.mpi-cbg.de","threadId":"18774","inReplyTo":"7vfxgjub7c.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Add a simple getpass() for MinGW","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-08T02:56:21Z","receivedAt":"2009-04-08T02:56:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 7 Apr 2009, Junio C Hamano wrote:\n\n> Thanks; should I take this directly or via Hannes's pull request?\n\nThanks for asking; Maybe Hannes has some alternative solution, so I'd like \nto have his take on things first.\n\nCiao,\nDscho \"who really, really needs to sleep now\"\n"},{"id":"110952","messageId":"49DE5120.8050904@kdbg.org","threadId":"18774","inReplyTo":"7ba615a300fe2742e8d32f0313c6ee9a1a1aaed3.1239154140u.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] Add a simple getpass() for MinGW","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-04-09T19:48:48Z","receivedAt":"2009-04-09T19:48:48Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin schrieb:\n> This should be replaced with a graphical getpass() at some stage.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> \n> \tI saw it coming that I had to do this.\n\nThere are two callers of getpass: One is in imap-send.c, but we don't \nbuild it on Windows. The other is in http.c. But notice that this is only \nbuilt if NO_CURL is not defined, yet, upstream git defines it in the MinGW \nsection, and so this patch alone is not needed in upstream git.\n\nI see you have removed NO_CURL = YesPlease in 4msysgit.git. You should \nmake it a part of a series that removes NO_CURL = YesPlease from the MinGW \nsection.\n\n>  compat/mingw.c |   15 +++++++++++++++\n>  1 files changed, 15 insertions(+), 0 deletions(-)\n> \n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index d50186e..2ab5bbe 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -1157,3 +1157,18 @@ int link(const char *oldpath, const char *newpath)\n>  \t}\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\nWhere do the callers get the prototype from (on MinGW)? Usually, we have \nto have a corresponding function declaration in compat/mingw.h for \nfunctions that are missing on Windows.\n\n From http://opengroup.org/onlinepubs/007908775/xsh/getpass.html:\n\n   The return value points to static data whose content may be overwritten\n   by each call.\n\nI'm not saying that you should use a fixed-size static character array, \nbut only that you should not leak memory on each call ;) (But not even \nthat is very important; I'm just summarizing the research I did because I \nwas wondering what would happen to the returned buffer.)\n\nApart from that, the implementation looks good. (_getch(), according to \nthe docs on MSDN, doesn't echo the input.)\n\n-- Hannes\n"},{"id":"111017","messageId":"alpine.DEB.1.00.0904102001340.10279@pacific.mpi-cbg.de","threadId":"18774","inReplyTo":"49DE5120.8050904@kdbg.org","subject":"Re: [PATCH] Add a simple getpass() for MinGW","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-10T18:03:07Z","receivedAt":"2009-04-10T18:03:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 9 Apr 2009, Johannes Sixt wrote:\n\n> Johannes Schindelin schrieb:\n> > This should be replaced with a graphical getpass() at some stage.\n> > \n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> > \n> >  I saw it coming that I had to do this.\n> \n> There are two callers of getpass: One is in imap-send.c, but we don't \n> build it on Windows. The other is in http.c. But notice that this is \n> only built if NO_CURL is not defined, yet, upstream git defines it in \n> the MinGW section, and so this patch alone is not needed in upstream \n> git.\n> \n> I see you have removed NO_CURL = YesPlease in 4msysgit.git. You should \n> make it a part of a series that removes NO_CURL = YesPlease from the \n> MinGW section.\n\nIndeed we did, as we ship curl, and we rely on http:// protocol being \navailable in the netinstaller.\n\n> >  compat/mingw.c |   15 +++++++++++++++\n> >  1 files changed, 15 insertions(+), 0 deletions(-)\n> > \n> > diff --git a/compat/mingw.c b/compat/mingw.c\n> > index d50186e..2ab5bbe 100644\n> > --- a/compat/mingw.c\n> > +++ b/compat/mingw.c\n> > @@ -1157,3 +1157,18 @@ int link(const char *oldpath, const char *newpath)\n> >   }\n> >   return 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> Where do the callers get the prototype from (on MinGW)? Usually, we have to\n> have a corresponding function declaration in compat/mingw.h for functions that\n> are missing on Windows.\n> \n> From http://opengroup.org/onlinepubs/007908775/xsh/getpass.html:\n> \n>   The return value points to static data whose content may be overwritten\n>   by each call.\n> \n> I'm not saying that you should use a fixed-size static character array, but\n> only that you should not leak memory on each call ;) (But not even that is\n> very important; I'm just summarizing the research I did because I was\n> wondering what would happen to the returned buffer.)\n\nGood catch!\n\nWill fix.\n\n> Apart from that, the implementation looks good. (_getch(), according to \n> the docs on MSDN, doesn't echo the input.)\n\nI'll probably add handling for ^H (as I need it very often ;-), but not \nfor ^W (overkill).\n\nCiao,\nDscho\n"}]}