{"thread":{"id":"22823","subject":"[PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","startedAt":"2010-02-26T00:07:25Z","lastAt":"2010-02-26T17:41:02Z","messageCount":5,"participants":["Frank Li","Junio C Hamano","Eric Wong","Johannes Sixt"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"135704","messageId":"1267142845-3040-1-git-send-email-lznuaa@gmail.com","threadId":"22823","inReplyTo":"3.SQo","subject":"[PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","fromName":"Frank Li","fromEmail":"lznuaa@gmail.com","sentAt":"2010-02-26T00:07:25Z","receivedAt":"2010-02-26T00:07:25Z","isPatch":true,"sender":{"key":"lznuaa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40642?v=4"},"body":"git-svn reads passwords from an interactive terminal.\nThis behavior cause GUIs to hang waiting for git-svn to\ncomplete\n\nFix this problem by allowing a password-retrieving command\nto be specified in GIT_ASKPASS. SSH_ASKPASS is supported\nas a fallback when GIT_ASKPASS is not provided.\n\nSigned-off-by: Frank Li <lznuaa@gmail.com>\n---\n git-svn.perl |   37 +++++++++++++++++++++++++++----------\n 1 files changed, 27 insertions(+), 10 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 265852f..cd39792 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -31,6 +31,16 @@ if (! exists $ENV{SVN_SSH}) {\n \t}\n }\n \n+if (! exists $ENV{GIT_ASKPASS}) {\n+\tif (exists $ENV{SSH_ASKPASS}) {\n+\t\t$ENV{GIT_ASKPASS} = $ENV{SSH_ASKPASS};\n+\t\tif ($^O eq 'msys') {\n+                        $ENV{GIT_ASKPASS} =~ s/\\\\/\\\\\\\\/g;\n+                        $ENV{GIT_ASKPASS} =~ s/(.*)/\"$1\"/;\n+                }\n+\t}\n+}\n+\n $Git::SVN::Log::TZ = $ENV{TZ};\n $ENV{TZ} = 'UTC';\n $| = 1; # unbuffer STDOUT\n@@ -3966,18 +3976,25 @@ sub username {\n \n sub _read_password {\n \tmy ($prompt, $realm) = @_;\n-\tprint STDERR $prompt;\n-\tSTDERR->flush;\n-\trequire Term::ReadKey;\n-\tTerm::ReadKey::ReadMode('noecho');\n \tmy $password = '';\n-\twhile (defined(my $key = Term::ReadKey::ReadKey(0))) {\n-\t\tlast if $key =~ /[\\012\\015]/; # \\n\\r\n-\t\t$password .= $key;\n+\tif (exists $ENV{GIT_ASKPASS}) {\n+\t\topen(PH, \"$ENV{GIT_ASKPASS} \\\"$prompt\\\" |\");\n+\t\t$password = <PH>;\n+\t\t$password =~ s/[\\012\\015]//; # \\n\\r\n+\t\tclose(PH);\n+\t} else {\n+\t\tprint STDERR $prompt;\n+\t\tSTDERR->flush;\n+\t\trequire Term::ReadKey;\n+\t\tTerm::ReadKey::ReadMode('noecho');\n+\t\twhile (defined(my $key = Term::ReadKey::ReadKey(0))) {\n+\t\t\tlast if $key =~ /[\\012\\015]/; # \\n\\r\n+\t\t\t$password .= $key;\n+\t\t}\n+\t\tTerm::ReadKey::ReadMode('restore');\n+\t\tprint STDERR \"\\n\";\n+\t\tSTDERR->flush;\n \t}\n-\tTerm::ReadKey::ReadMode('restore');\n-\tprint STDERR \"\\n\";\n-\tSTDERR->flush;\n \t$password;\n }\n \n-- \n1.7.0.85.g37fda.dirty\n"},{"id":"135735","messageId":"7vzl2wa4m0.fsf@alter.siamese.dyndns.org","threadId":"22823","inReplyTo":"1267142845-3040-1-git-send-email-lznuaa@gmail.com","subject":"Re: [PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-26T06:33:11Z","receivedAt":"2010-02-26T06:33:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Frank Li <lznuaa@gmail.com> writes:\n\n> +if (! exists $ENV{GIT_ASKPASS}) {\n> +\tif (exists $ENV{SSH_ASKPASS}) {\n> +\t\t$ENV{GIT_ASKPASS} = $ENV{SSH_ASKPASS};\n> +\t\tif ($^O eq 'msys') {\n> +                        $ENV{GIT_ASKPASS} =~ s/\\\\/\\\\\\\\/g;\n> +                        $ENV{GIT_ASKPASS} =~ s/(.*)/\"$1\"/;\n> +                }\n> +\t}\n> +}\n\nI've seen this code before, and you may not be the best person to answer\nthis question, but this worries me and puzzles me a bit.\n\nOn msys (and nowhere else), SSH_ASKPASS can be used as given by the user\nto launch the prompter, but GIT_ASKPASS must be quoted in some funny way.\n\nWhy is that?  Does this mean they must be given differently by the end\nuser?  In other words, if the end user wants to set GIT_ASKPASS himself,\ns/he needs to do this funny quoting, that is different from SSH_ASKPASS.\n\nI also notice that git-gui has support for SSH_ASKPASS (and its own\nimplementation).  Does it have the same quoting issues on msys?\n\nThe reason I am asking is because:\n\n (1) if SSH_ASKPASS and GIT_ASKPASS cannot be specified exactly the same\n     way, then [PATCH 3/3] would probably need a similar quoting magic?\n\n (2) With [PATCH 3/3], with quoting magic if necessary, we wouldn't need\n     the above hunk, as it has already be done by the \"git\" potty.\n"},{"id":"135740","messageId":"1976ea661002260055l63a9ea53x8dc4dfd90cbac199@mail.gmail.com","threadId":"22823","inReplyTo":"7vzl2wa4m0.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","fromName":"Frank Li","fromEmail":"lznuaa@gmail.com","sentAt":"2010-02-26T08:55:58Z","receivedAt":"2010-02-26T08:55:58Z","isPatch":true,"sender":{"key":"lznuaa@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40642?v=4"},"body":"2010/2/26 Junio C Hamano <gitster@pobox.com>:\n> Frank Li <lznuaa@gmail.com> writes:\n>\n>> +if (! exists $ENV{GIT_ASKPASS}) {\n>> +     if (exists $ENV{SSH_ASKPASS}) {\n>> +             $ENV{GIT_ASKPASS} = $ENV{SSH_ASKPASS};\n>> +             if ($^O eq 'msys') {\n>> +                        $ENV{GIT_ASKPASS} =~ s/\\\\/\\\\\\\\/g;\n>> +                        $ENV{GIT_ASKPASS} =~ s/(.*)/\"$1\"/;\n>> +                }\n>> +     }\n>> +}\n>\n> I've seen this code before, and you may not be the best person to answer\n> this question, but this worries me and puzzles me a bit.\n\nYes, I copy it from fall back SVN_SSH from GIT_SSH at git-svn.perl.\n\nI guess it seems related with windows path using space, such as\nc:\\program files\\bin\\xxx.\nperl Open ('$ENV{GIT_ASKPASS} |\") will be changed to open(\"c:\\program\nfiles\\bin\\xxx |\").\nPerl will think c:\\program as application, files\\bin\\xxx as first parameter.\n\nSo add \".  it equal to open ( \"\\\"c:\\program files\\bin\\xxx\\\" |\"). perl\ncan run correct application.\n\n>\n> On msys (and nowhere else), SSH_ASKPASS can be used as given by the user\n> to launch the prompter, but GIT_ASKPASS must be quoted in some funny way.\n>\n> Why is that?  Does this mean they must be given differently by the end\n> user?  In other words, if the end user wants to set GIT_ASKPASS himself,\n> s/he needs to do this funny quoting, that is different from SSH_ASKPASS.\n\nI should add code to check if there are a space at GIT_ASKPASS,\nif there are space in prompter path, add quote.\nSo end user set GIT_ASKPASS and SSH_ASKPASS at the same ways,  NO quoting.\n\n>\n> I also notice that git-gui has support for SSH_ASKPASS (and its own\n> implementation).  Does it have the same quoting issues on msys?\n\nI think no because msys add prompter to PATH environment and needn't\nset full path.\n\n>\n> The reason I am asking is because:\n>\n>  (1) if SSH_ASKPASS and GIT_ASKPASS cannot be specified exactly the same\n>     way, then [PATCH 3/3] would probably need a similar quoting magic?\n\nSSH_ASKPASS and GIT_ASKPASS is the same.  C code needn't quoting\nbecause start_command think $GIT_ASKPASS is full path and don't split\n$GIT_ASKPASS to\napplication and parameter by space.\n\n>\n>  (2) With [PATCH 3/3], with quoting magic if necessary, we wouldn't need\n>     the above hunk, as it has already be done by the \"git\" potty.\n>\n\nquoting magic is not necessary at PATCH 3/3.\n"},{"id":"135746","messageId":"20100226100525.GC22579@dcvr.yhbt.net","threadId":"22823","inReplyTo":"1267142845-3040-1-git-send-email-lznuaa@gmail.com","subject":"Re: [PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2010-02-26T10:05:25Z","receivedAt":"2010-02-26T10:05:25Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Frank Li <lznuaa@gmail.com> wrote:\n> git-svn reads passwords from an interactive terminal.\n> This behavior cause GUIs to hang waiting for git-svn to\n> complete\n> \n> Fix this problem by allowing a password-retrieving command\n> to be specified in GIT_ASKPASS. SSH_ASKPASS is supported\n> as a fallback when GIT_ASKPASS is not provided.\n> \n> Signed-off-by: Frank Li <lznuaa@gmail.com>\n> ---\n>  git-svn.perl |   37 +++++++++++++++++++++++++++----------\n>  1 files changed, 27 insertions(+), 10 deletions(-)\n> \n> diff --git a/git-svn.perl b/git-svn.perl\n> index 265852f..cd39792 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -31,6 +31,16 @@ if (! exists $ENV{SVN_SSH}) {\n>  \t}\n>  }\n>  \n> +if (! exists $ENV{GIT_ASKPASS}) {\n> +\tif (exists $ENV{SSH_ASKPASS}) {\n> +\t\t$ENV{GIT_ASKPASS} = $ENV{SSH_ASKPASS};\n> +\t\tif ($^O eq 'msys') {\n> +                        $ENV{GIT_ASKPASS} =~ s/\\\\/\\\\\\\\/g;\n> +                        $ENV{GIT_ASKPASS} =~ s/(.*)/\"$1\"/;\n> +                }\n> +\t}\n> +}\n> +\n\nHi Frank,\n\nSince this logic isn't SVN-specific, can we get this in Git.pm\nand/or git-var so other tools can use it?\n\nThanks\n\n-- \nEric Wong\n"},{"id":"135762","messageId":"4B8807AE.2090502@kdbg.org","threadId":"22823","inReplyTo":"1267142845-3040-1-git-send-email-lznuaa@gmail.com","subject":"Re: [PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2010-02-26T17:41:02Z","receivedAt":"2010-02-26T17:41:02Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Frank Li schrieb:\n> +if (! exists $ENV{GIT_ASKPASS}) {\n> +\tif (exists $ENV{SSH_ASKPASS}) {\n> +\t\t$ENV{GIT_ASKPASS} = $ENV{SSH_ASKPASS};\n> +\t\tif ($^O eq 'msys') {\n> +                        $ENV{GIT_ASKPASS} =~ s/\\\\/\\\\\\\\/g;\n> +                        $ENV{GIT_ASKPASS} =~ s/(.*)/\"$1\"/;\n\nDon't quote GIT_ASKPASS here.\n\n> +\tif (exists $ENV{GIT_ASKPASS}) {\n> +\t\topen(PH, \"$ENV{GIT_ASKPASS} \\\"$prompt\\\" |\");\n\n\t\topen(PH, \"-|\", $ENV{GIT_ASKPASS}, $prompt);\n\nand you don't have to do any quoting at all, no?\n\n-- Hannes\n"}]}