git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-remote-mediawiki: use git.pm functions for credentials
@ 2013-06-04 11:11 benoit.person
  2013-06-04 18:44 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: benoit.person @ 2013-06-04 11:11 UTC (permalink / raw)
  To: git; +Cc: celestin.matte, Benoit Person, Matthieu Moy

From: Benoit Person <benoit.person@ensimag.fr>

In 52dce6d, a new credential function was added to git.pm, based on
git-remote-mediawiki's functions. The logical follow-up is to use
those functions in git-remote-mediawiki.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl | 66 ++++-------------------------
 1 file changed, 9 insertions(+), 57 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 9c14c1f..9fb281e 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -13,6 +13,7 @@
 
 use strict;
 use MediaWiki::API;
+use Git;
 use DateTime::Format::ISO8601;
 
 # By default, use UTF-8 to communicate with Git and the user
@@ -156,57 +157,6 @@ while (<STDIN>) {
 
 ########################## Functions ##############################
 
-## credential API management (generic functions)
-
-sub credential_read {
-	my %credential;
-	my $reader = shift;
-	my $op = shift;
-	while (<$reader>) {
-		my ($key, $value) = /([^=]*)=(.*)/;
-		if (not defined $key) {
-			die "ERROR receiving response from git credential $op:\n$_\n";
-		}
-		$credential{$key} = $value;
-	}
-	return %credential;
-}
-
-sub credential_write {
-	my $credential = shift;
-	my $writer = shift;
-	# url overwrites other fields, so it must come first
-	print $writer "url=$credential->{url}\n" if exists $credential->{url};
-	while (my ($key, $value) = each(%$credential) ) {
-		if (length $value && $key ne 'url') {
-			print $writer "$key=$value\n";
-		}
-	}
-}
-
-sub credential_run {
-	my $op = shift;
-	my $credential = shift;
-	my $pid = open2(my $reader, my $writer, "git credential $op");
-	credential_write($credential, $writer);
-	print $writer "\n";
-	close($writer);
-
-	if ($op eq "fill") {
-		%$credential = credential_read($reader, $op);
-	} else {
-		if (<$reader>) {
-			die "ERROR while running git credential $op:\n$_";
-		}
-	}
-	close($reader);
-	waitpid($pid, 0);
-	my $child_exit_status = $? >> 8;
-	if ($child_exit_status != 0) {
-		die "'git credential $op' failed with code $child_exit_status.";
-	}
-}
-
 # MediaWiki API instance, created lazily.
 my $mediawiki;
 
@@ -217,22 +167,24 @@ sub mw_connect_maybe {
 	$mediawiki = MediaWiki::API->new;
 	$mediawiki->{config}->{api_url} = "$url/api.php";
 	if ($wiki_login) {
-		my %credential = (url => $url);
-		$credential{username} = $wiki_login;
-		$credential{password} = $wiki_passwd;
-		credential_run("fill", \%credential);
+		my %credential = (
+			'url' => $url,
+			'username' => $wiki_login,
+			'password' => $wiki_passwd
+		);
+		Git::credential \%credential;
 		my $request = {lgname => $credential{username},
 			       lgpassword => $credential{password},
 			       lgdomain => $wiki_domain};
 		if ($mediawiki->login($request)) {
-			credential_run("approve", \%credential);
+			Git::credential \%credential, 'approve';
 			print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
 		} else {
 			print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
 			print STDERR "  (error " .
 				$mediawiki->{error}->{code} . ': ' .
 				$mediawiki->{error}->{details} . ")\n";
-			credential_run("reject", \%credential);
+			Git::credential \%credential, 'reject';
 			exit 1;
 		}
 	}
-- 
1.8.3.rc3.7.gc2f33ed.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-remote-mediawiki: use git.pm functions for credentials
  2013-06-04 11:11 [PATCH] git-remote-mediawiki: use git.pm functions for credentials benoit.person
@ 2013-06-04 18:44 ` Junio C Hamano
  2013-06-05 10:58   ` [PATCH] git-remote-mediawiki: use Git.pm " benoit.person
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2013-06-04 18:44 UTC (permalink / raw)
  To: benoit.person; +Cc: git, celestin.matte, Benoit Person, Matthieu Moy

benoit.person@gmail.com writes:

> From: Benoit Person <benoit.person@ensimag.fr>
>
> In 52dce6d, a new credential function was added to git.pm, based on
> git-remote-mediawiki's functions. The logical follow-up is to use
> those functions in git-remote-mediawiki.
>
> Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
> ---
>  contrib/mw-to-git/git-remote-mediawiki.perl | 66 ++++-------------------------
>  1 file changed, 9 insertions(+), 57 deletions(-)

With s/git.pm/Git.pm/, the above looks perfect.

> @@ -217,22 +167,24 @@ sub mw_connect_maybe {
>  	$mediawiki = MediaWiki::API->new;
>  	$mediawiki->{config}->{api_url} = "$url/api.php";
>  	if ($wiki_login) {
> -		my %credential = (url => $url);
> -		$credential{username} = $wiki_login;
> -		$credential{password} = $wiki_passwd;
> -		credential_run("fill", \%credential);
> +		my %credential = (
> +			'url' => $url,
> +			'username' => $wiki_login,
> +			'password' => $wiki_passwd
> +		);
> +		Git::credential \%credential;
>  		my $request = {lgname => $credential{username},
>  			       lgpassword => $credential{password},
>  			       lgdomain => $wiki_domain};
>  		if ($mediawiki->login($request)) {
> -			credential_run("approve", \%credential);
> +			Git::credential \%credential, 'approve';

The example in perl/Git.pm for =item credential shows the subroutine
call without surrounding parentheses, and that is perfectly valid
Perl, but given that the prevalent style of subroutine calls made in
this file seems to be with them, i.e. subr(arg, arg), you might want
to consider being consistent here (and in the implicit 'fill' call
several lines above, and 'reject' call below).

Thanks.

>  			print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
>  		} else {
>  			print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
>  			print STDERR "  (error " .
>  				$mediawiki->{error}->{code} . ': ' .
>  				$mediawiki->{error}->{details} . ")\n";
> -			credential_run("reject", \%credential);
> +			Git::credential \%credential, 'reject';
>  			exit 1;
>  		}
>  	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] git-remote-mediawiki: use Git.pm functions for credentials
  2013-06-04 18:44 ` Junio C Hamano
@ 2013-06-05 10:58   ` benoit.person
  2013-06-05 15:55     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: benoit.person @ 2013-06-05 10:58 UTC (permalink / raw)
  To: git; +Cc: celestin.matte, gitster, Benoit Person, Matthieu Moy

From: Benoit Person <benoit.person@ensimag.fr>

In 52dce6d, a new credential function was added to Git.pm, based on
git-remote-mediawiki's functions. The logical follow-up is to use
those functions in git-remote-mediawiki.

Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl | 66 ++++-------------------------
 1 file changed, 9 insertions(+), 57 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 9c14c1f..6672e4c 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -13,6 +13,7 @@
 
 use strict;
 use MediaWiki::API;
+use Git;
 use DateTime::Format::ISO8601;
 
 # By default, use UTF-8 to communicate with Git and the user
@@ -156,57 +157,6 @@ while (<STDIN>) {
 
 ########################## Functions ##############################
 
-## credential API management (generic functions)
-
-sub credential_read {
-	my %credential;
-	my $reader = shift;
-	my $op = shift;
-	while (<$reader>) {
-		my ($key, $value) = /([^=]*)=(.*)/;
-		if (not defined $key) {
-			die "ERROR receiving response from git credential $op:\n$_\n";
-		}
-		$credential{$key} = $value;
-	}
-	return %credential;
-}
-
-sub credential_write {
-	my $credential = shift;
-	my $writer = shift;
-	# url overwrites other fields, so it must come first
-	print $writer "url=$credential->{url}\n" if exists $credential->{url};
-	while (my ($key, $value) = each(%$credential) ) {
-		if (length $value && $key ne 'url') {
-			print $writer "$key=$value\n";
-		}
-	}
-}
-
-sub credential_run {
-	my $op = shift;
-	my $credential = shift;
-	my $pid = open2(my $reader, my $writer, "git credential $op");
-	credential_write($credential, $writer);
-	print $writer "\n";
-	close($writer);
-
-	if ($op eq "fill") {
-		%$credential = credential_read($reader, $op);
-	} else {
-		if (<$reader>) {
-			die "ERROR while running git credential $op:\n$_";
-		}
-	}
-	close($reader);
-	waitpid($pid, 0);
-	my $child_exit_status = $? >> 8;
-	if ($child_exit_status != 0) {
-		die "'git credential $op' failed with code $child_exit_status.";
-	}
-}
-
 # MediaWiki API instance, created lazily.
 my $mediawiki;
 
@@ -217,22 +167,24 @@ sub mw_connect_maybe {
 	$mediawiki = MediaWiki::API->new;
 	$mediawiki->{config}->{api_url} = "$url/api.php";
 	if ($wiki_login) {
-		my %credential = (url => $url);
-		$credential{username} = $wiki_login;
-		$credential{password} = $wiki_passwd;
-		credential_run("fill", \%credential);
+		my %credential = (
+			'url' => $url,
+			'username' => $wiki_login,
+			'password' => $wiki_passwd
+		);
+		Git::credential(\%credential);
 		my $request = {lgname => $credential{username},
 			       lgpassword => $credential{password},
 			       lgdomain => $wiki_domain};
 		if ($mediawiki->login($request)) {
-			credential_run("approve", \%credential);
+			Git::credential(\%credential, 'approve');
 			print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
 		} else {
 			print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
 			print STDERR "  (error " .
 				$mediawiki->{error}->{code} . ': ' .
 				$mediawiki->{error}->{details} . ")\n";
-			credential_run("reject", \%credential);
+			Git::credential(\%credential, 'reject');
 			exit 1;
 		}
 	}
-- 
1.8.3.rc3.7.gc2f33ed.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-remote-mediawiki: use Git.pm functions for credentials
  2013-06-05 10:58   ` [PATCH] git-remote-mediawiki: use Git.pm " benoit.person
@ 2013-06-05 15:55     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2013-06-05 15:55 UTC (permalink / raw)
  To: benoit.person; +Cc: git, celestin.matte, gitster, Matthieu Moy

On Wed, Jun 05, 2013 at 12:58:00PM +0200, benoit.person@ensimag.fr wrote:

> From: Benoit Person <benoit.person@ensimag.fr>
> 
> In 52dce6d, a new credential function was added to Git.pm, based on
> git-remote-mediawiki's functions. The logical follow-up is to use
> those functions in git-remote-mediawiki.
> 
> Signed-off-by: Benoit Person <benoit.person@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>

Thanks, this looks correct to me.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-05 15:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-04 11:11 [PATCH] git-remote-mediawiki: use git.pm functions for credentials benoit.person
2013-06-04 18:44 ` Junio C Hamano
2013-06-05 10:58   ` [PATCH] git-remote-mediawiki: use Git.pm " benoit.person
2013-06-05 15:55     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).