On Sat, Jun 09, 2012 at 08:53:48PM +0200, Javier.Roucher-Iglesias@xxxxxxxxxxxxxxx wrote: > diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki > index c18bfa1..4b14d78 100755 > --- a/contrib/mw-to-git/git-remote-mediawiki > +++ b/contrib/mw-to-git/git-remote-mediawiki > @@ -152,28 +152,111 @@ while (<STDIN>) { > ########################## Functions ############################## > > # MediaWiki API instance, created lazily. > +sub run_credential { Is there any reason not to add this to perl/Git.pm? I suspect that other scripts will want to use it, too (for example, send-email could probably use it for SMTP credentials). > + if (scalar(@_) == 2) { > + if ($_[1] eq ("store" || "cache")) { > + run_git("config credential.helper \'$_[1]\'"); > + } else { > + print STDERR "ERROR: run_credential (fill|approve|reject) [store|cache]\n"; > + exit 1; > + } > + } This hunk looks wrong. You should never be setting the credential.helper config; that is the responsibility of the user to set, as they want to select whatever helper is appropriate. Nor do you need to care about which helpers are in use; the point of git-credential is that it will do that for you. > + my $parsed = URI->new($url); > + $cre_protocol = $parsed->scheme; > + $cre_host = $parsed->host; > + $cre_path = $parsed->path; > + > + if ($wiki_login ne "") { > + $msg .= "username=$wiki_login\n"; > + } > + if ($wiki_passwd ne "") { > + $msg .= "password=$wiki_passwd\n"; > + } > + if ($cre_protocol ne "") { > + $msg .= "protocol=$cre_protocol\n"; > + } > + if ($cre_host ne "") { > + $msg .= "host=$cre_host\n"; > + } > + if ($cre_path ne "") { > + $msg .= "path=$cre_path\n"; > + } > + > + $msg .= "\n"; All of this could just go away for the "fill" case if we allow URLs on the command line (see my previous email if you haven't already). And for the "approve" and "reject" cases, we could just save the result from "fill" and feed it back verbatim, as I described in the earlier email. Then it would be as simple as: sub fill_credential { my $quoted_url = quotemeta(shift); my $verbatim = `git credential fill $quoted_url`; $? and die "git-credential failed"; $verbatim =~ /^username=(.*)$/m or die "git-credential did not give us a username"; my $username = $1; $verbatim =~ /^password=(.*)$/m or die "git-credential did not give us a password"; return ($username, $password, $verbatim); } sub report_credential { my ($type, $verbatim) = @_; open(my $fh, '|-', "git credential $type"); print $fh $verbatim; } > + my $key; > + my $value; > + my $Prog = "git credential $op"; > + open2(*Reader, *Writer, $Prog); > + print Writer $msg; > + close (Writer); > + > + if ($op eq "fill") { > + while (<Reader>) { > + my ($key, $value) = /([^=]*)=(.*)/; > + # error if key undef > + if (not defined $key) { > + print STDERR "ERROR reciving reponse git credential fill\n"; > + exit 1; > + } > + if ($key eq "username") { > + $wiki_login = $value; > + } > + if ($key eq "password") { > + $wiki_passwd = $value; > + } > + } > + } else { > + while (<Reader>) { > + print STDERR "\nERROR while running git credential $op:\n$_"; > + } > + } > +} This isn't a good way to check for errors. The non-fill actions will never produce output on stdout, and you are not intercepting their stderr. Besides which, checking for errors by reading stderr is not a good practice; you should check the return value of the command in $? after it finishes. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html