We can just feed our URL straight to git-credential and it
will parse it for us, saving us some code.

Signed-off-by: Jeff King <p...@peff.net>
---
 contrib/mw-to-git/git-remote-mediawiki | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki 
b/contrib/mw-to-git/git-remote-mediawiki
index b06f27b..c9ac416 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -163,32 +163,6 @@ while (<STDIN>) {
 
 ## credential API management (generic functions)
 
-sub credential_from_url {
-       my $url = shift;
-       my $parsed = URI->new($url);
-       my %credential;
-
-       if ($parsed->scheme) {
-               $credential{protocol} = $parsed->scheme;
-       }
-       if ($parsed->host) {
-               $credential{host} = $parsed->host;
-       }
-       if ($parsed->path) {
-               $credential{path} = $parsed->path;
-       }
-       if ($parsed->userinfo) {
-               if ($parsed->userinfo =~ /([^:]*):(.*)/) {
-                       $credential{username} = $1;
-                       $credential{password} = $2;
-               } else {
-                       $credential{username} = $parsed->userinfo;
-               }
-       }
-
-       return %credential;
-}
-
 sub credential_read {
        my %credential;
        my $reader = shift;
@@ -216,7 +190,9 @@ sub credential_write {
 sub credential_run {
        my $op = shift;
        my $credential = shift;
+       my $url = shift;
        my $pid = open2(my $reader, my $writer, "git credential $op");
+       print $writer "url=$url\n" if defined $url;
        credential_write($credential, $writer);
        print $writer "\n";
        close($writer);
@@ -246,10 +222,10 @@ sub mw_connect_maybe {
        $mediawiki = MediaWiki::API->new;
        $mediawiki->{config}->{api_url} = "$url/api.php";
        if ($wiki_login) {
-               my %credential = credential_from_url($url);
+               my %credential;
                $credential{username} = $wiki_login;
                $credential{password} = $wiki_passwd;
-               credential_run("fill", \%credential);
+               credential_run("fill", \%credential, $url);
                my $request = {lgname => $credential{username},
                               lgpassword => $credential{password},
                               lgdomain => $wiki_domain};
-- 
1.7.10.5.40.g059818d
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to