git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/28] Follow perlcritic's recommandations
@ 2013-06-09 22:22 Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer Célestin Matte
                   ` (28 more replies)
  0 siblings, 29 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Changes with v2:
- Remove patch [02/22] about using the Readonly module
- Split commit [07/22] into 5 different ones
- Split commit [14/22] into 2 different ones
- Patch [17/22] was *not* split: tell me if it is necessary
- Remove wrong change in patch [22/22]

Patch about fixing a bug in a regexp (with has been renames "Make a regexp
clearer"), which had been sent as a separate patch, is reintegrated into this
series of patches.

Changes with v1:
- split first commit into 6 different commits
- remove commit [17/18] about moving open() call
- took every other comment into account

Célestin Matte (28):
  git-remote-mediawiki: Make a regexp clearer
  git-remote-mediawiki: Move "use warnings;" before any instruction
  git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8)
  git-remote-mediawiki: Always end a subroutine with a return
  git-remote-mediawiki: Move a variable declaration at the top of the
    code
  git-remote-mediawiki: Change syntax of map calls
  git-remote-mediawiki: Rewrite unclear line of instructions
  git-remote-mediawiki: Remove useless regexp modifier (m)
  git-remote-mediawiki: Change the behaviour of a split
  git-remote-mediawiki: Change separator of some regexps
  git-remote-mediawiki: Change style in a regexp
  git-remote-mediawiki: Change style in a regexp
  git-remote-mediawiki: Add newline in the end of die() error messages
  git-remote-mediawiki: Change the name of a variable
  git-remote-mediawiki: Turn double-negated expressions into simple
    expressions
  git-remote-mediawiki: Remove unused variable $entry
  git-remote-mediawiki: Rename a variable ($last) which has the name of
    a keyword
  git-remote-mediawiki: Assign a variable as undef and make proper
    indentation
  git-remote-mediawiki: Check return value of open
  git-remote-mediawiki: remove import of unused open2
  git-remote-mediawiki: Put long code into a subroutine
  git-remote-mediawiki: Modify strings for a better coding-style
  git-remote-mediawiki: Brace file handles for print for more clarity
  git-remote-mediawiki: Replace "unless" statements with negated "if"
    statements
  git-remote-mediawiki: Don't use quotes for empty strings
  git-remote-mediawiki: Put non-trivial numeric values in constants.
  git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki")
  git-remote-mediawiki: Clearly rewrite double dereference

 contrib/mw-to-git/git-remote-mediawiki.perl |  534 +++++++++++++++------------
 1 file changed, 288 insertions(+), 246 deletions(-)

-- 
1.7.9.5

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

* [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 02/28] git-remote-mediawiki: Move "use warnings;" before any instruction Célestin Matte
                   ` (27 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Perl's split function takes a regex pattern argument. You can also
feed it an expression, which is then compiled into a regex at runtime.
It therefore works to pass your pattern via single quotes, but it is
much less obvious to a reader that the argument is meant to be a
regex, not a static string. Using the traditional slash-delimiters
makes this easier to read.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 410eae9..a7bb397 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1170,7 +1170,7 @@ sub mw_push_revision {
 		# history (linearized with --first-parent)
 		print STDERR "Warning: no common ancestor, pushing complete history\n";
 		my $history = run_git("rev-list --first-parent --children $local");
-		my @history = split('\n', $history);
+		my @history = split(/\n/, $history);
 		@history = @history[1..$#history];
 		foreach my $line (reverse @history) {
 			my @commit_info_split = split(/ |\n/, $line);
-- 
1.7.9.5

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

* [PATCH v3 02/28] git-remote-mediawiki: Move "use warnings;" before any instruction
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 03/28] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8) Célestin Matte
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index a7bb397..863ecc9 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -15,6 +15,7 @@ use strict;
 use MediaWiki::API;
 use Git;
 use DateTime::Format::ISO8601;
+use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
 binmode STDERR, ":utf8";
@@ -23,8 +24,6 @@ binmode STDOUT, ":utf8";
 use URI::Escape;
 use IPC::Open2;
 
-use warnings;
-
 # Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced
 use constant SLASH_REPLACEMENT => "%2F";
 
-- 
1.7.9.5

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

* [PATCH v3 03/28] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8)
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 02/28] git-remote-mediawiki: Move "use warnings;" before any instruction Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 04/28] git-remote-mediawiki: Always end a subroutine with a return Célestin Matte
                   ` (25 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Follow perlcritic's InputOutput::RequireEncodingWithUTF8Layer policy

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 863ecc9..5e198e0 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -18,8 +18,8 @@ use DateTime::Format::ISO8601;
 use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
-binmode STDERR, ":utf8";
-binmode STDOUT, ":utf8";
+binmode STDERR, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
 
 use URI::Escape;
 use IPC::Open2;
@@ -587,7 +587,7 @@ sub literal_data_raw {
 	utf8::downgrade($content);
 	binmode STDOUT, ":raw";
 	print STDOUT "data ", bytes::length($content), "\n", $content;
-	binmode STDOUT, ":utf8";
+	binmode STDOUT, ":encoding(UTF-8)";
 }
 
 sub mw_capabilities {
-- 
1.7.9.5

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

* [PATCH v3 04/28] git-remote-mediawiki: Always end a subroutine with a return
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (2 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 03/28] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8) Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 05/28] git-remote-mediawiki: Move a variable declaration at the top of the code Célestin Matte
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Follow Subroutines::RequireFinalReturn

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 5e198e0..f19b276 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -197,12 +197,14 @@ sub mw_connect_maybe {
 			exit 1;
 		}
 	}
+	return;
 }
 
 ## Functions for listing pages on the remote wiki
 sub get_mw_tracked_pages {
 	my $pages = shift;
 	get_mw_page_list(\@tracked_pages, $pages);
+	return;
 }
 
 sub get_mw_page_list {
@@ -218,6 +220,7 @@ sub get_mw_page_list {
 		get_mw_first_pages(\@slice, $pages);
 		@some_pages = @some_pages[51..$#some_pages];
 	}
+	return;
 }
 
 sub get_mw_tracked_categories {
@@ -240,6 +243,7 @@ sub get_mw_tracked_categories {
 			$pages->{$page->{title}} = $page;
 		}
 	}
+	return;
 }
 
 sub get_mw_all_pages {
@@ -259,6 +263,7 @@ sub get_mw_all_pages {
 	foreach my $page (@{$mw_pages}) {
 		$pages->{$page->{title}} = $page;
 	}
+	return;
 }
 
 # queries the wiki for a set of pages. Meant to be used within a loop
@@ -289,6 +294,7 @@ sub get_mw_first_pages {
 			$pages->{$page->{title}} = $page;
 		}
 	}
+	return;
 }
 
 # Get the list of pages to be fetched according to configuration.
@@ -357,6 +363,7 @@ sub get_all_mediafiles {
 	foreach my $page (@{$mw_pages}) {
 		$pages->{$page->{title}} = $page;
 	}
+	return;
 }
 
 sub get_linked_mediafiles {
@@ -403,6 +410,7 @@ sub get_linked_mediafiles {
 
 		@titles = @titles[($batch+1)..$#titles];
 	}
+	return;
 }
 
 sub get_mw_mediafile_for_page_revision {
@@ -578,6 +586,7 @@ sub mediawiki_smudge_filename {
 sub literal_data {
 	my ($content) = @_;
 	print STDOUT "data ", bytes::length($content), "\n", $content;
+	return;
 }
 
 sub literal_data_raw {
@@ -588,6 +597,7 @@ sub literal_data_raw {
 	binmode STDOUT, ":raw";
 	print STDOUT "data ", bytes::length($content), "\n", $content;
 	binmode STDOUT, ":encoding(UTF-8)";
+	return;
 }
 
 sub mw_capabilities {
@@ -599,6 +609,7 @@ sub mw_capabilities {
 	print STDOUT "list\n";
 	print STDOUT "push\n";
 	print STDOUT "\n";
+	return;
 }
 
 sub mw_list {
@@ -607,11 +618,13 @@ sub mw_list {
 	print STDOUT "? refs/heads/master\n";
 	print STDOUT "\@refs/heads/master HEAD\n";
 	print STDOUT "\n";
+	return;
 }
 
 sub mw_option {
 	print STDERR "remote-helper command 'option $_[0]' not yet implemented\n";
 	print STDOUT "unsupported\n";
+	return;
 }
 
 sub fetch_mw_revisions_for_page {
@@ -733,6 +746,7 @@ sub import_file_revision {
 	print STDOUT "N inline :$n\n";
 	literal_data("mediawiki_revision: " . $commit{mw_revision});
 	print STDOUT "\n\n";
+	return;
 }
 
 # parse a sequence of
@@ -753,6 +767,7 @@ sub get_more_refs {
 			die("Invalid command in a '$cmd' batch: ". $_);
 		}
 	}
+	return;
 }
 
 sub mw_import {
@@ -762,6 +777,7 @@ sub mw_import {
 		mw_import_ref($ref);
 	}
 	print STDOUT "done\n";
+	return;
 }
 
 sub mw_import_ref {
@@ -805,6 +821,7 @@ sub mw_import_ref {
 		# thrown saying that HEAD is referring to unknown object 0000000000000000000
 		# and the clone fails.
 	}
+	return;
 }
 
 sub mw_import_ref_by_pages {
@@ -1111,6 +1128,7 @@ sub mw_push {
 		print STDERR "  git pull --rebase\n";
 		print STDERR "\n";
 	}
+	return;
 }
 
 sub mw_push_revision {
-- 
1.7.9.5

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

* [PATCH v3 05/28] git-remote-mediawiki: Move a variable declaration at the top of the code
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (3 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 04/28] git-remote-mediawiki: Always end a subroutine with a return Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 06/28] git-remote-mediawiki: Change syntax of map calls Célestin Matte
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

%basetimestamps declaration was lost in the middle of subroutines

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index f19b276..fe1343d 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -95,6 +95,9 @@ unless ($fetch_strategy) {
 	$fetch_strategy = "by_page";
 }
 
+# Remember the timestamp corresponding to a revision id.
+my %basetimestamps;
+
 # Dumb push: don't update notes and mediawiki ref to reflect the last push.
 #
 # Configurable with mediawiki.dumbPush, or per-remote with
@@ -480,9 +483,6 @@ sub get_last_local_revision {
 	return $lastrevision_number;
 }
 
-# Remember the timestamp corresponding to a revision id.
-my %basetimestamps;
-
 # Get the last remote revision without taking in account which pages are
 # tracked or not. This function makes a single request to the wiki thus
 # avoid a loop onto all tracked pages. This is useful for the fetch-by-rev
-- 
1.7.9.5

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

* [PATCH v3 06/28] git-remote-mediawiki: Change syntax of map calls
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (4 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 05/28] git-remote-mediawiki: Move a variable declaration at the top of the code Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Put first parameter of map inside a block, for better readability.
Follow BuiltinFunctions::RequireBlockMap

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index fe1343d..431e063 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -371,7 +371,7 @@ sub get_all_mediafiles {
 
 sub get_linked_mediafiles {
 	my $pages = shift;
-	my @titles = map $_->{title}, values(%{$pages});
+	my @titles = map { $_->{title} } values(%{$pages});
 
 	# The query is split in small batches because of the MW API limit of
 	# the number of links to be returned (500 links max).
@@ -399,11 +399,13 @@ sub get_linked_mediafiles {
 		while (my ($id, $page) = each(%{$result->{query}->{pages}})) {
 			my @media_titles;
 			if (defined($page->{links})) {
-				my @link_titles = map $_->{title}, @{$page->{links}};
+				my @link_titles
+				    = map { $_->{title} } @{$page->{links}};
 				push(@media_titles, @link_titles);
 			}
 			if (defined($page->{images})) {
-				my @image_titles = map $_->{title}, @{$page->{images}};
+				my @image_titles
+				    = map { $_->{title} } @{$page->{images}};
 				push(@media_titles, @image_titles);
 			}
 			if (@media_titles) {
@@ -833,7 +835,7 @@ sub mw_import_ref_by_pages {
 	my ($n, @revisions) = fetch_mw_revisions(\@pages, $fetch_from);
 
 	@revisions = sort {$a->{revid} <=> $b->{revid}} @revisions;
-	my @revision_ids = map $_->{revid}, @revisions;
+	my @revision_ids = map { $_->{revid} } @revisions;
 
 	return mw_import_revids($fetch_from, \@revision_ids, \%pages_hash);
 }
@@ -1246,8 +1248,8 @@ sub get_allowed_file_extensions {
 		siprop => 'fileextensions'
 		};
 	my $result = $mediawiki->api($query);
-	my @file_extensions= map $_->{ext},@{$result->{query}->{fileextensions}};
-	my %hashFile = map {$_ => 1}@file_extensions;
+	my @file_extensions = map { $_->{ext}} @{$result->{query}->{fileextensions}};
+	my %hashFile = map { $_ => 1 } @file_extensions;
 
 	return %hashFile;
 }
-- 
1.7.9.5

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

* [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (5 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 06/28] git-remote-mediawiki: Change syntax of map calls Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-11 15:04   ` Junio C Hamano
  2013-06-09 22:22 ` [PATCH v3 08/28] git-remote-mediawiki: Remove useless regexp modifier (m) Célestin Matte
                   ` (21 subsequent siblings)
  28 siblings, 1 reply; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Subroutines' parameters should be affected to variable before doing anything
else
Besides, existing instruction affected a variable inside a "if", which break
Git's coding style

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 431e063..2db6467 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1333,7 +1333,8 @@ sub get_mw_namespace_id {
 }
 
 sub get_mw_namespace_id_for_page {
-	if (my ($namespace) = $_[0] =~ /^([^:]*):/) {
+	my $namespace = shift;
+	if ($namespace =~ /^([^:]*):/) {
 		return get_mw_namespace_id($namespace);
 	} else {
 		return;
-- 
1.7.9.5

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

* [PATCH v3 08/28] git-remote-mediawiki: Remove useless regexp modifier (m)
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (6 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

m// and // is used randomly. It is better to use the m modifier only when
needed, e.g., when the regexp uses another separator than //.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 2db6467..7ce640f 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -761,7 +761,7 @@ sub get_more_refs {
 	my @refs;
 	while (1) {
 		my $line = <STDIN>;
-		if ($line =~ m/^$cmd (.*)$/) {
+		if ($line =~ /^$cmd (.*)$/) {
 			push(@refs, $1);
 		} elsif ($line eq "\n") {
 			return @refs;
@@ -1167,11 +1167,11 @@ sub mw_push_revision {
 		my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents $local ^$parsed_sha1"));
 		my %local_ancestry;
 		foreach my $line (@local_ancestry) {
-			if (my ($child, $parents) = $line =~ m/^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
+			if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
 				foreach my $parent (split(' ', $parents)) {
 					$local_ancestry{$parent} = $child;
 				}
-			} elsif (!$line =~ m/^([a-f0-9]+)/) {
+			} elsif (!$line =~ /^([a-f0-9]+)/) {
 				die "Unexpected output from git rev-list: $line";
 			}
 		}
-- 
1.7.9.5

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

* [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (7 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 08/28] git-remote-mediawiki: Remove useless regexp modifier (m) Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-10  8:29   ` Matthieu Moy
  2013-06-09 22:22 ` [PATCH v3 10/28] git-remote-mediawiki: Change separator of some regexps Célestin Matte
                   ` (19 subsequent siblings)
  28 siblings, 1 reply; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

A "split ' '" is turned into a "split / /", which changes its behaviour: the
old method matched a run of whtespaces (/\s*/), while the new one will match a
single whitespace, which is what we want here. Indeed, in other contexts,
changing split(' ') to split(/ /) could potentially be a regression, however,
here, when parsing the output of "rev-list --parents", whose output SHA-1's are
each separated by a single space, splitting on a single space is perfectly
correct.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 7ce640f..7537305 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1168,7 +1168,7 @@ sub mw_push_revision {
 		my %local_ancestry;
 		foreach my $line (@local_ancestry) {
 			if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
-				foreach my $parent (split(' ', $parents)) {
+				foreach my $parent (split(/ /, $parents)) {
 					$local_ancestry{$parent} = $child;
 				}
 			} elsif (!$line =~ /^([a-f0-9]+)/) {
-- 
1.7.9.5

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

* [PATCH v3 10/28] git-remote-mediawiki: Change separator of some regexps
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (8 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 11/28] git-remote-mediawiki: Change style in a regexp Célestin Matte
                   ` (18 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Use {}{} instead of /// when slashes are used inside the regexp so as not to
escape it.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 7537305..b01d402 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -120,7 +120,7 @@ chomp($dumb_push);
 $dumb_push = ($dumb_push eq "true");
 
 my $wiki_name = $url;
-$wiki_name =~ s/[^\/]*:\/\///;
+$wiki_name =~ s{[^/]*://}{};
 # If URL is like http://user:password@example.com/, we clearly don't
 # want the password in $wiki_name. While we're there, also remove user
 # and '@' sign, to avoid author like MWUser@HTTPUser@host.com
@@ -564,7 +564,7 @@ sub mediawiki_smudge {
 
 sub mediawiki_clean_filename {
 	my $filename = shift;
-	$filename =~ s/@{[SLASH_REPLACEMENT]}/\//g;
+	$filename =~ s{@{[SLASH_REPLACEMENT]}}{/}g;
 	# [, ], |, {, and } are forbidden by MediaWiki, even URL-encoded.
 	# Do a variant of URL-encoding, i.e. looks like URL-encoding,
 	# but with _ added to prevent MediaWiki from thinking this is
@@ -578,7 +578,7 @@ sub mediawiki_clean_filename {
 
 sub mediawiki_smudge_filename {
 	my $filename = shift;
-	$filename =~ s/\//@{[SLASH_REPLACEMENT]}/g;
+	$filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;
 	$filename =~ s/ /_/g;
 	# Decode forbidden characters encoded in mediawiki_clean_filename
 	$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf("%c", hex($1))/ge;
-- 
1.7.9.5

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

* [PATCH v3 11/28] git-remote-mediawiki: Change style in a regexp
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (9 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 10/28] git-remote-mediawiki: Change separator of some regexps Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 12/28] " Célestin Matte
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

In this regexp, ' |\n' is used, whereas its equivalent '[ \n]', which is
clearer, is used elsewhere. Make the style coherent.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index b01d402..267c164 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1192,7 +1192,7 @@ sub mw_push_revision {
 		my @history = split(/\n/, $history);
 		@history = @history[1..$#history];
 		foreach my $line (reverse @history) {
-			my @commit_info_split = split(/ |\n/, $line);
+			my @commit_info_split = split(/[ \n]/, $line);
 			push(@commit_pairs, \@commit_info_split);
 		}
 	}
-- 
1.7.9.5

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

* [PATCH v3 12/28] git-remote-mediawiki: Change style in a regexp
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (10 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 11/28] git-remote-mediawiki: Change style in a regexp Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 13/28] git-remote-mediawiki: Add newline in the end of die() error messages Célestin Matte
                   ` (16 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Change '[\n]' to '\n': brackets are useless here.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 267c164..86229a1 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1271,7 +1271,7 @@ sub get_mw_namespace_id {
 		# Look at configuration file, if the record for that namespace is
 		# already cached. Namespaces are stored in form:
 		# "Name_of_namespace:Id_namespace", ex.: "File:6".
-		my @temp = split(/[\n]/, run_git("config --get-all remote."
+		my @temp = split(/\n/, run_git("config --get-all remote."
 						. $remotename .".namespaceCache"));
 		chomp(@temp);
 		foreach my $ns (@temp) {
-- 
1.7.9.5

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

* [PATCH v3 13/28] git-remote-mediawiki: Add newline in the end of die() error messages
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (11 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 12/28] " Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 14/28] git-remote-mediawiki: Change the name of a variable Célestin Matte
                   ` (15 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 86229a1..44c5e0e 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -135,16 +135,16 @@ while (<STDIN>) {
 	if (defined($cmd[0])) {
 		# Line not blank
 		if ($cmd[0] eq "capabilities") {
-			die("Too many arguments for capabilities") unless (!defined($cmd[1]));
+			die("Too many arguments for capabilities\n") unless (!defined($cmd[1]));
 			mw_capabilities();
 		} elsif ($cmd[0] eq "list") {
-			die("Too many arguments for list") unless (!defined($cmd[2]));
+			die("Too many arguments for list\n") unless (!defined($cmd[2]));
 			mw_list($cmd[1]);
 		} elsif ($cmd[0] eq "import") {
-			die("Invalid arguments for import") unless ($cmd[1] ne "" && !defined($cmd[2]));
+			die("Invalid arguments for import\n") unless ($cmd[1] ne "" && !defined($cmd[2]));
 			mw_import($cmd[1]);
 		} elsif ($cmd[0] eq "option") {
-			die("Too many arguments for option") unless ($cmd[1] ne "" && $cmd[2] ne "" && !defined($cmd[3]));
+			die("Too many arguments for option\n") unless ($cmd[1] ne "" && $cmd[2] ne "" && !defined($cmd[3]));
 			mw_option($cmd[1],$cmd[2]);
 		} elsif ($cmd[0] eq "push") {
 			mw_push($cmd[1]);
@@ -241,7 +241,7 @@ sub get_mw_tracked_categories {
 			cmtitle => $category,
 			cmlimit => 'max' } )
 			|| die $mediawiki->{error}->{code} . ': '
-				. $mediawiki->{error}->{details};
+				. $mediawiki->{error}->{details} . "\n";
 		foreach my $page (@{$mw_pages}) {
 			$pages->{$page->{title}} = $page;
 		}
@@ -766,7 +766,7 @@ sub get_more_refs {
 		} elsif ($line eq "\n") {
 			return @refs;
 		} else {
-			die("Invalid command in a '$cmd' batch: ". $_);
+			die("Invalid command in a '$cmd' batch: $_\n");
 		}
 	}
 	return;
@@ -878,7 +878,7 @@ sub mw_import_revids {
 		my $result = $mediawiki->api($query);
 
 		if (!$result) {
-			die "Failed to retrieve modified page for revision $pagerevid";
+			die "Failed to retrieve modified page for revision $pagerevid\n";
 		}
 
 		if (defined($result->{query}->{badrevids}->{$pagerevid})) {
@@ -887,7 +887,7 @@ sub mw_import_revids {
 		}
 
 		if (!defined($result->{query}->{pages})) {
-			die "Invalid revision $pagerevid.";
+			die "Invalid revision $pagerevid.\n";
 		}
 
 		my @result_pages = values(%{$result->{query}->{pages}});
@@ -998,7 +998,7 @@ sub mw_upload_file {
 			}, {
 				skip_encoding => 1
 			} ) || die $mediawiki->{error}->{code} . ':'
-				 . $mediawiki->{error}->{details};
+				 . $mediawiki->{error}->{details} . "\n";
 			my $last_file_page = $mediawiki->get_page({title => $path});
 			$newrevid = $last_file_page->{revid};
 			print STDERR "Pushed file: $new_sha1 - $complete_file_name.\n";
@@ -1078,7 +1078,7 @@ sub mw_push_file {
 				# Other errors. Shouldn't happen => just die()
 				die 'Fatal: Error ' .
 				    $mediawiki->{error}->{code} .
-				    ' from mediwiki: ' . $mediawiki->{error}->{details};
+				    ' from mediwiki: ' . $mediawiki->{error}->{details} . "\n";
 			}
 		}
 		$newrevid = $result->{edit}->{newrevid};
@@ -1100,7 +1100,7 @@ sub mw_push {
 	my $pushed;
 	for my $refspec (@refsspecs) {
 		my ($force, $local, $remote) = $refspec =~ /^(\+)?([^:]*):([^:]*)$/
-		    or die("Invalid refspec for push. Expected <src>:<dst> or +<src>:<dst>");
+		    or die("Invalid refspec for push. Expected <src>:<dst> or +<src>:<dst>\n");
 		if ($force) {
 			print STDERR "Warning: forced push not allowed on a MediaWiki.\n";
 		}
@@ -1172,7 +1172,7 @@ sub mw_push_revision {
 					$local_ancestry{$parent} = $child;
 				}
 			} elsif (!$line =~ /^([a-f0-9]+)/) {
-				die "Unexpected output from git rev-list: $line";
+				die "Unexpected output from git rev-list: $line\n";
 			}
 		}
 		while ($parsed_sha1 ne $HEAD_sha1) {
@@ -1226,7 +1226,7 @@ sub mw_push_revision {
 				return error_non_fast_forward($remote);
 			}
 			if ($status ne "ok") {
-				die("Unknown error from mw_push_file()");
+				die("Unknown error from mw_push_file()\n");
 			}
 		}
 		unless ($dumb_push) {
-- 
1.7.9.5

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

* [PATCH v3 14/28] git-remote-mediawiki: Change the name of a variable
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (12 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 13/28] git-remote-mediawiki: Add newline in the end of die() error messages Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 15/28] git-remote-mediawiki: Turn double-negated expressions into simple expressions Célestin Matte
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Local variable $url has the same name as a global variable. Changing the name
of the local variable prevents future possible misunderstanding.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 44c5e0e..63d1530 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -454,14 +454,14 @@ sub get_mw_mediafile_for_page_revision {
 }
 
 sub download_mw_mediafile {
-	my $url = shift;
+	my $download_url = shift;
 
-	my $response = $mediawiki->{ua}->get($url);
+	my $response = $mediawiki->{ua}->get($download_url);
 	if ($response->code == 200) {
 		return $response->decoded_content;
 	} else {
 		print STDERR "Error downloading mediafile from :\n";
-		print STDERR "URL: $url\n";
+		print STDERR "URL: $download_url\n";
 		print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
 		exit 1;
 	}
-- 
1.7.9.5

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

* [PATCH v3 15/28] git-remote-mediawiki: Turn double-negated expressions into simple expressions
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (13 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 14/28] git-remote-mediawiki: Change the name of a variable Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 16/28] git-remote-mediawiki: Remove unused variable $entry Célestin Matte
                   ` (13 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 63d1530..6024791 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -135,16 +135,16 @@ while (<STDIN>) {
 	if (defined($cmd[0])) {
 		# Line not blank
 		if ($cmd[0] eq "capabilities") {
-			die("Too many arguments for capabilities\n") unless (!defined($cmd[1]));
+			die("Too many arguments for capabilities\n") if (defined($cmd[1]));
 			mw_capabilities();
 		} elsif ($cmd[0] eq "list") {
-			die("Too many arguments for list\n") unless (!defined($cmd[2]));
+			die("Too many arguments for list\n") if (defined($cmd[2]));
 			mw_list($cmd[1]);
 		} elsif ($cmd[0] eq "import") {
-			die("Invalid arguments for import\n") unless ($cmd[1] ne "" && !defined($cmd[2]));
+			die("Invalid arguments for import\n") if ($cmd[1] eq "" || defined($cmd[2]));
 			mw_import($cmd[1]);
 		} elsif ($cmd[0] eq "option") {
-			die("Too many arguments for option\n") unless ($cmd[1] ne "" && $cmd[2] ne "" && !defined($cmd[3]));
+			die("Too many arguments for option\n") if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
 			mw_option($cmd[1],$cmd[2]);
 		} elsif ($cmd[0] eq "push") {
 			mw_push($cmd[1]);
-- 
1.7.9.5

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

* [PATCH v3 16/28] git-remote-mediawiki: Remove unused variable $entry
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (14 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 15/28] git-remote-mediawiki: Turn double-negated expressions into simple expressions Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 17/28] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword Célestin Matte
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 6024791..ef9e60a 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -127,7 +127,6 @@ $wiki_name =~ s{[^/]*://}{};
 $wiki_name =~ s/^.*@//;
 
 # Commands parser
-my $entry;
 my @cmd;
 while (<STDIN>) {
 	chomp;
-- 
1.7.9.5

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

* [PATCH v3 17/28] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (15 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 16/28] git-remote-mediawiki: Remove unused variable $entry Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 18/28] git-remote-mediawiki: Assign a variable as undef and make proper indentation Célestin Matte
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index ef9e60a..0610daa 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -214,11 +214,11 @@ sub get_mw_page_list {
 	my $pages = shift;
 	my @some_pages = @$page_list;
 	while (@some_pages) {
-		my $last = 50;
-		if ($#some_pages < $last) {
-			$last = $#some_pages;
+		my $last_page = 50;
+		if ($#some_pages < $last_page) {
+			$last_page = $#some_pages;
 		}
-		my @slice = @some_pages[0..$last];
+		my @slice = @some_pages[0..$last_page];
 		get_mw_first_pages(\@slice, $pages);
 		@some_pages = @some_pages[51..$#some_pages];
 	}
-- 
1.7.9.5

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

* [PATCH v3 18/28] git-remote-mediawiki: Assign a variable as undef and make proper indentation
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (16 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 17/28] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 19/28] git-remote-mediawiki: Check return value of open Célestin Matte
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Explicitly assign local variable $/ as undef and make a proper
one-instruction-by-line indentation

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 0610daa..50b3452 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -338,7 +338,10 @@ sub run_git {
 	my $args = shift;
 	my $encoding = (shift || "encoding(UTF-8)");
 	open(my $git, "-|:$encoding", "git " . $args);
-	my $res = do { local $/; <$git> };
+	my $res = do { 
+		local $/ = undef;
+		<$git>
+	};
 	close($git);
 
 	return $res;
-- 
1.7.9.5

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

* [PATCH v3 19/28] git-remote-mediawiki: Check return value of open
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (17 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 18/28] git-remote-mediawiki: Assign a variable as undef and make proper indentation Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 20/28] git-remote-mediawiki: remove import of unused open2 Célestin Matte
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 50b3452..fb6bca3 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -337,7 +337,8 @@ sub get_mw_pages {
 sub run_git {
 	my $args = shift;
 	my $encoding = (shift || "encoding(UTF-8)");
-	open(my $git, "-|:$encoding", "git " . $args);
+	open(my $git, "-|:$encoding", "git " . $args)
+	    or die "Unable to open: $!\n";
 	my $res = do { 
 		local $/ = undef;
 		<$git>
-- 
1.7.9.5

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

* [PATCH v3 20/28] git-remote-mediawiki: remove import of unused open2
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (18 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 19/28] git-remote-mediawiki: Check return value of open Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index fb6bca3..c404e7b 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -22,7 +22,6 @@ binmode STDERR, ":encoding(UTF-8)";
 binmode STDOUT, ":encoding(UTF-8)";
 
 use URI::Escape;
-use IPC::Open2;
 
 # Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced
 use constant SLASH_REPLACEMENT => "%2F";
-- 
1.7.9.5

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

* [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (19 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 20/28] git-remote-mediawiki: remove import of unused open2 Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-11 15:42   ` Junio C Hamano
  2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
                   ` (7 subsequent siblings)
  28 siblings, 1 reply; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   50 +++++++++++++++++----------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index c404e7b..a66cef4 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -126,28 +126,13 @@ $wiki_name =~ s{[^/]*://}{};
 $wiki_name =~ s/^.*@//;
 
 # Commands parser
-my @cmd;
+my @cmds;
 while (<STDIN>) {
 	chomp;
-	@cmd = split(/ /);
-	if (defined($cmd[0])) {
+	@cmds = split(/ /);
+	if (defined($cmds[0])) {
 		# Line not blank
-		if ($cmd[0] eq "capabilities") {
-			die("Too many arguments for capabilities\n") if (defined($cmd[1]));
-			mw_capabilities();
-		} elsif ($cmd[0] eq "list") {
-			die("Too many arguments for list\n") if (defined($cmd[2]));
-			mw_list($cmd[1]);
-		} elsif ($cmd[0] eq "import") {
-			die("Invalid arguments for import\n") if ($cmd[1] eq "" || defined($cmd[2]));
-			mw_import($cmd[1]);
-		} elsif ($cmd[0] eq "option") {
-			die("Too many arguments for option\n") if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
-			mw_option($cmd[1],$cmd[2]);
-		} elsif ($cmd[0] eq "push") {
-			mw_push($cmd[1]);
-		} else {
-			print STDERR "Unknown command. Aborting...\n";
+		if (!parse_command(\@cmds)) {
 			last;
 		}
 	} else {
@@ -167,6 +152,33 @@ sub exit_error_usage {
     die "ERROR: git-remote-mediawiki module was not called with a correct number of parameters\n";
 }
 
+sub parse_command {
+	my $cmdref = shift;
+	my @cmd = @{$cmdref};
+	if ($cmd[0] eq "capabilities") {
+		die("Too many arguments for capabilities\n")
+		    if (defined($cmd[1]));
+		mw_capabilities();
+	} elsif ($cmd[0] eq "list") {
+		die("Too many arguments for list\n") if (defined($cmd[2]));
+		mw_list($cmd[1]);
+	} elsif ($cmd[0] eq "import") {
+		die("Invalid arguments for import\n")
+		    if ($cmd[1] eq "" || defined($cmd[2]));
+		mw_import($cmd[1]);
+	} elsif ($cmd[0] eq "option") {
+		die("Too many arguments for option\n")
+		    if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
+		mw_option($cmd[1],$cmd[2]);
+	} elsif ($cmd[0] eq "push") {
+		mw_push($cmd[1]);
+	} else {
+		print STDERR "Unknown command. Aborting...\n";
+		return 0;
+	}
+	return 1;
+}
+
 # MediaWiki API instance, created lazily.
 my $mediawiki;
 
-- 
1.7.9.5

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

* [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (20 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-10  0:50   ` Eric Sunshine
  2013-06-10  8:37   ` Matthieu Moy
  2013-06-09 22:22 ` [PATCH v3 23/28] git-remote-mediawiki: Brace file handles for print for more clarity Célestin Matte
                   ` (6 subsequent siblings)
  28 siblings, 2 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

- strings which don't need interpolation are single-quoted for more clarity and
slight gain of performance
- interpolation is preferred over concatenation in many cases, for more clarity
- variables are always used with the ${} operator inside strings
- strings including double-quotes are written with qq() so that the quotes do
not have to be escaped

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |  242 +++++++++++++--------------
 1 file changed, 120 insertions(+), 122 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index a66cef4..efc376a 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -18,13 +18,13 @@ use DateTime::Format::ISO8601;
 use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
-binmode STDERR, ":encoding(UTF-8)";
-binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ':encoding(UTF-8)';
+binmode STDOUT, ':encoding(UTF-8)';
 
 use URI::Escape;
 
 # Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced
-use constant SLASH_REPLACEMENT => "%2F";
+use constant SLASH_REPLACEMENT => '%2F';
 
 # It's not always possible to delete pages (may require some
 # privileges). Deleted pages are replaced with this content.
@@ -35,7 +35,7 @@ use constant DELETED_CONTENT => "[[Category:Deleted]]\n";
 use constant EMPTY_CONTENT => "<!-- empty page -->\n";
 
 # used to reflect file creation or deletion in diff.
-use constant NULL_SHA1 => "0000000000000000000000000000000000000000";
+use constant NULL_SHA1 => '0000000000000000000000000000000000000000';
 
 # Used on Git's side to reflect empty edit messages on the wiki
 use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
@@ -49,35 +49,35 @@ my $url = $ARGV[1];
 
 # Accept both space-separated and multiple keys in config file.
 # Spaces should be written as _ anyway because we'll use chomp.
-my @tracked_pages = split(/[ \n]/, run_git("config --get-all remote.". $remotename .".pages"));
+my @tracked_pages = split(/[ \n]/, run_git("config --get-all remote.${remotename}.pages"));
 chomp(@tracked_pages);
 
 # Just like @tracked_pages, but for MediaWiki categories.
-my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.". $remotename .".categories"));
+my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
 chomp(@tracked_categories);
 
 # Import media files on pull
-my $import_media = run_git("config --get --bool remote.". $remotename .".mediaimport");
+my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
 chomp($import_media);
-$import_media = ($import_media eq "true");
+$import_media = ($import_media eq 'true');
 
 # Export media files on push
-my $export_media = run_git("config --get --bool remote.". $remotename .".mediaexport");
+my $export_media = run_git("config --get --bool remote.${remotename}.mediaexport");
 chomp($export_media);
-$export_media = !($export_media eq "false");
+$export_media = !($export_media eq 'false');
 
-my $wiki_login = run_git("config --get remote.". $remotename .".mwLogin");
+my $wiki_login = run_git("config --get remote.${remotename}.mwLogin");
 # Note: mwPassword is discourraged. Use the credential system instead.
-my $wiki_passwd = run_git("config --get remote.". $remotename .".mwPassword");
-my $wiki_domain = run_git("config --get remote.". $remotename .".mwDomain");
+my $wiki_passwd = run_git("config --get remote.${remotename}.mwPassword");
+my $wiki_domain = run_git("config --get remote.${remotename}.mwDomain");
 chomp($wiki_login);
 chomp($wiki_passwd);
 chomp($wiki_domain);
 
 # Import only last revisions (both for clone and fetch)
-my $shallow_import = run_git("config --get --bool remote.". $remotename .".shallow");
+my $shallow_import = run_git("config --get --bool remote.${remotename}.shallow");
 chomp($shallow_import);
-$shallow_import = ($shallow_import eq "true");
+$shallow_import = ($shallow_import eq 'true');
 
 # Fetch (clone and pull) by revisions instead of by pages. This behavior
 # is more efficient when we have a wiki with lots of pages and we fetch
@@ -85,13 +85,13 @@ $shallow_import = ($shallow_import eq "true");
 # Possible values:
 # - by_rev: perform one query per new revision on the remote wiki
 # - by_page: query each tracked page for new revision
-my $fetch_strategy = run_git("config --get remote.$remotename.fetchStrategy");
+my $fetch_strategy = run_git("config --get remote.${remotename}.fetchStrategy");
 unless ($fetch_strategy) {
-	$fetch_strategy = run_git("config --get mediawiki.fetchStrategy");
+	$fetch_strategy = run_git('config --get mediawiki.fetchStrategy');
 }
 chomp($fetch_strategy);
 unless ($fetch_strategy) {
-	$fetch_strategy = "by_page";
+	$fetch_strategy = 'by_page';
 }
 
 # Remember the timestamp corresponding to a revision id.
@@ -111,12 +111,12 @@ my %basetimestamps;
 # will get the history with information lost). If the import is
 # deterministic, this means everybody gets the same sha1 for each
 # MediaWiki revision.
-my $dumb_push = run_git("config --get --bool remote.$remotename.dumbPush");
+my $dumb_push = run_git("config --get --bool remote.${remotename}.dumbPush");
 unless ($dumb_push) {
-	$dumb_push = run_git("config --get --bool mediawiki.dumbPush");
+	$dumb_push = run_git('config --get --bool mediawiki.dumbPush');
 }
 chomp($dumb_push);
-$dumb_push = ($dumb_push eq "true");
+$dumb_push = ($dumb_push eq 'true');
 
 my $wiki_name = $url;
 $wiki_name =~ s{[^/]*://}{};
@@ -155,22 +155,22 @@ sub exit_error_usage {
 sub parse_command {
 	my $cmdref = shift;
 	my @cmd = @{$cmdref};
-	if ($cmd[0] eq "capabilities") {
+	if ($cmd[0] eq 'capabilities') {
 		die("Too many arguments for capabilities\n")
 		    if (defined($cmd[1]));
 		mw_capabilities();
-	} elsif ($cmd[0] eq "list") {
+	} elsif ($cmd[0] eq 'list') {
 		die("Too many arguments for list\n") if (defined($cmd[2]));
 		mw_list($cmd[1]);
-	} elsif ($cmd[0] eq "import") {
+	} elsif ($cmd[0] eq 'import') {
 		die("Invalid arguments for import\n")
 		    if ($cmd[1] eq "" || defined($cmd[2]));
 		mw_import($cmd[1]);
-	} elsif ($cmd[0] eq "option") {
+	} elsif ($cmd[0] eq 'option') {
 		die("Too many arguments for option\n")
 		    if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
 		mw_option($cmd[1],$cmd[2]);
-	} elsif ($cmd[0] eq "push") {
+	} elsif ($cmd[0] eq 'push') {
 		mw_push($cmd[1]);
 	} else {
 		print STDERR "Unknown command. Aborting...\n";
@@ -187,7 +187,7 @@ sub mw_connect_maybe {
 		return;
 	}
 	$mediawiki = MediaWiki::API->new;
-	$mediawiki->{config}->{api_url} = "$url/api.php";
+	$mediawiki->{config}->{api_url} = "${url}/api.php";
 	if ($wiki_login) {
 		my %credential = (
 			'url' => $url,
@@ -200,10 +200,10 @@ sub mw_connect_maybe {
 			       lgdomain => $wiki_domain};
 		if ($mediawiki->login($request)) {
 			Git::credential \%credential, 'approve';
-			print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
+			print STDERR qq(Logged in mediawiki user "$credential{username}".\n);
 		} else {
-			print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
-			print STDERR "  (error " .
+			print STDERR qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);
+			print STDERR '  (error ' .
 				$mediawiki->{error}->{code} . ': ' .
 				$mediawiki->{error}->{details} . ")\n";
 			Git::credential \%credential, 'reject';
@@ -243,7 +243,7 @@ sub get_mw_tracked_categories {
 			# Mediawiki requires the Category
 			# prefix, but let's not force the user
 			# to specify it.
-			$category = "Category:" . $category;
+			$category = "Category:${category}";
 		}
 		my $mw_pages = $mediawiki->list( {
 			action => 'query',
@@ -269,8 +269,8 @@ sub get_mw_all_pages {
 	});
 	if (!defined($mw_pages)) {
 		print STDERR "fatal: could not get the list of wiki pages.\n";
-		print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
+		print STDERR "fatal: '${url}' does not appear to be a mediawiki\n";
+		print STDERR "fatal: make sure '${url}/api.php' is a valid page.\n";
 		exit 1;
 	}
 	foreach my $page (@{$mw_pages}) {
@@ -296,8 +296,8 @@ sub get_mw_first_pages {
 	});
 	if (!defined($mw_pages)) {
 		print STDERR "fatal: could not query the list of wiki pages.\n";
-		print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
+		print STDERR "fatal: '${url}' does not appear to be a mediawiki\n";
+		print STDERR "fatal: make sure '${url}/api.php' is a valid page.\n";
 		exit 1;
 	}
 	while (my ($id, $page) = each(%{$mw_pages->{query}->{pages}})) {
@@ -347,10 +347,10 @@ sub get_mw_pages {
 #        $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
 sub run_git {
 	my $args = shift;
-	my $encoding = (shift || "encoding(UTF-8)");
-	open(my $git, "-|:$encoding", "git " . $args)
-	    or die "Unable to open: $!\n";
-	my $res = do { 
+	my $encoding = (shift || 'encoding(UTF-8)');
+	open(my $git, "-|:${encoding}", "git ${args}")
+	    or die "Unable to fork: $!\n";
+	my $res = do {
 		local $/ = undef;
 		<$git>
 	};
@@ -368,7 +368,7 @@ sub get_all_mediafiles {
 	my $mw_pages = $mediawiki->list({
 		action => 'query',
 		list => 'allpages',
-		apnamespace => get_mw_namespace_id("File"),
+		apnamespace => get_mw_namespace_id('File'),
 		aplimit => 'max'
 	});
 	if (!defined($mw_pages)) {
@@ -405,7 +405,7 @@ sub get_linked_mediafiles {
 			action => 'query',
 			prop => 'links|images',
 			titles => $mw_titles,
-			plnamespace => get_mw_namespace_id("File"),
+			plnamespace => get_mw_namespace_id('File'),
 			pllimit => 'max'
 		};
 		my $result = $mediawiki->api($query);
@@ -443,7 +443,7 @@ sub get_mw_mediafile_for_page_revision {
 	my $query = {
 		action => 'query',
 		prop => 'imageinfo',
-		titles => "File:" . $filename,
+		titles => "File:${filename}",
 		iistart => $timestamp,
 		iiend => $timestamp,
 		iiprop => 'timestamp|archivename|url',
@@ -475,26 +475,26 @@ sub download_mw_mediafile {
 		return $response->decoded_content;
 	} else {
 		print STDERR "Error downloading mediafile from :\n";
-		print STDERR "URL: $download_url\n";
-		print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
+		print STDERR "URL: ${download_url}\n";
+		print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";
 		exit 1;
 	}
 }
 
 sub get_last_local_revision {
 	# Get note regarding last mediawiki revision
-	my $note = run_git("notes --ref=$remotename/mediawiki show refs/mediawiki/$remotename/master 2>/dev/null");
+	my $note = run_git("notes --ref=${remotename}/mediawiki show refs/mediawiki/${remotename}/master 2>/dev/null");
 	my @note_info = split(/ /, $note);
 
 	my $lastrevision_number;
-	if (!(defined($note_info[0]) && $note_info[0] eq "mediawiki_revision:")) {
-		print STDERR "No previous mediawiki revision found";
+	if (!(defined($note_info[0]) && $note_info[0] eq 'mediawiki_revision:')) {
+		print STDERR 'No previous mediawiki revision found';
 		$lastrevision_number = 0;
 	} else {
 		# Notes are formatted : mediawiki_revision: #number
 		$lastrevision_number = $note_info[1];
 		chomp($lastrevision_number);
-		print STDERR "Last local mediawiki revision found is $lastrevision_number";
+		print STDERR "Last local mediawiki revision found is ${lastrevision_number}";
 	}
 	return $lastrevision_number;
 }
@@ -573,7 +573,7 @@ sub mediawiki_smudge {
 		$string = "";
 	}
 	# This \n is important. This is due to mediawiki's way to handle end of files.
-	return $string."\n";
+	return "${string}\n";
 }
 
 sub mediawiki_clean_filename {
@@ -595,13 +595,13 @@ sub mediawiki_smudge_filename {
 	$filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;
 	$filename =~ s/ /_/g;
 	# Decode forbidden characters encoded in mediawiki_clean_filename
-	$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf("%c", hex($1))/ge;
+	$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf('%c', hex($1))/ge;
 	return $filename;
 }
 
 sub literal_data {
 	my ($content) = @_;
-	print STDOUT "data ", bytes::length($content), "\n", $content;
+	print STDOUT 'data ', bytes::length($content), "\n", $content;
 	return;
 }
 
@@ -620,7 +620,7 @@ sub mw_capabilities {
 	# Revisions are imported to the private namespace
 	# refs/mediawiki/$remotename/ by the helper and fetched into
 	# refs/remotes/$remotename later by fetch.
-	print STDOUT "refspec refs/heads/*:refs/mediawiki/$remotename/*\n";
+	print STDOUT "refspec refs/heads/*:refs/mediawiki/${remotename}/*\n";
 	print STDOUT "import\n";
 	print STDOUT "list\n";
 	print STDOUT "push\n";
@@ -679,7 +679,7 @@ sub fetch_mw_revisions_for_page {
 		@page_revs = sort {$b->{revid} <=> $a->{revid}} (@page_revs);
 		return $page_revs[0];
 	}
-	print STDERR "  Found ", $revnum, " revision(s).\n";
+	print STDERR "  Found ${revnum} revision(s).\n";
 	return @page_revs;
 }
 
@@ -691,8 +691,7 @@ sub fetch_mw_revisions {
 	my $n = 1;
 	foreach my $page (@pages) {
 		my $id = $page->{pageid};
-
-		print STDERR "page $n/", scalar(@pages), ": ". $page->{title} ."\n";
+		print STDERR "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";
 		$n++;
 		my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
 		@revisions = (@page_revs, @revisions);
@@ -706,7 +705,7 @@ sub fe_escape_path {
     $path =~ s/\\/\\\\/g;
     $path =~ s/"/\\"/g;
     $path =~ s/\n/\\n/g;
-    return '"' . $path . '"';
+    return qq("${path}");
 }
 
 sub import_file_revision {
@@ -726,41 +725,41 @@ sub import_file_revision {
 	my $author = $commit{author};
 	my $date = $commit{date};
 
-	print STDOUT "commit refs/mediawiki/$remotename/master\n";
-	print STDOUT "mark :$n\n";
-	print STDOUT "committer $author <$author\@$wiki_name> ", $date->epoch, " +0000\n";
+	print STDOUT "commit refs/mediawiki/${remotename}/master\n";
+	print STDOUT "mark :${n}\n";
+	print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
 	literal_data($comment);
 
 	# If it's not a clone, we need to know where to start from
 	if (!$full_import && $n == 1) {
-		print STDOUT "from refs/mediawiki/$remotename/master^0\n";
+		print STDOUT "from refs/mediawiki/${remotename}/master^0\n";
 	}
 	if ($content ne DELETED_CONTENT) {
-		print STDOUT "M 644 inline " .
-		    fe_escape_path($title . ".mw") . "\n";
+		print STDOUT 'M 644 inline ' .
+		    fe_escape_path("${title}.mw") . "\n";
 		literal_data($content);
 		if (%mediafile) {
-			print STDOUT "M 644 inline "
+			print STDOUT 'M 644 inline '
 			    . fe_escape_path($mediafile{title}) . "\n";
 			literal_data_raw($mediafile{content});
 		}
 		print STDOUT "\n\n";
 	} else {
-		print STDOUT "D " . fe_escape_path($title . ".mw") . "\n";
+		print STDOUT 'D ' . fe_escape_path("${title}.mw") . "\n";
 	}
 
 	# mediawiki revision number in the git note
 	if ($full_import && $n == 1) {
-		print STDOUT "reset refs/notes/$remotename/mediawiki\n";
+		print STDOUT "reset refs/notes/${remotename}/mediawiki\n";
 	}
-	print STDOUT "commit refs/notes/$remotename/mediawiki\n";
-	print STDOUT "committer $author <$author\@$wiki_name> ", $date->epoch, " +0000\n";
-	literal_data("Note added by git-mediawiki during import");
+	print STDOUT "commit refs/notes/${remotename}/mediawiki\n";
+	print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
+	literal_data('Note added by git-mediawiki during import');
 	if (!$full_import && $n == 1) {
-		print STDOUT "from refs/notes/$remotename/mediawiki^0\n";
+		print STDOUT "from refs/notes/${remotename}/mediawiki^0\n";
 	}
-	print STDOUT "N inline :$n\n";
-	literal_data("mediawiki_revision: " . $commit{mw_revision});
+	print STDOUT "N inline :${n}\n";
+	literal_data("mediawiki_revision: $commit{mw_revision}");
 	print STDOUT "\n\n";
 	return;
 }
@@ -788,7 +787,7 @@ sub get_more_refs {
 
 sub mw_import {
 	# multiple import commands can follow each other.
-	my @refs = (shift, get_more_refs("import"));
+	my @refs = (shift, get_more_refs('import'));
 	foreach my $ref (@refs) {
 		mw_import_ref($ref);
 	}
@@ -803,7 +802,7 @@ sub mw_import_ref {
 	# Since HEAD is a symbolic ref to master (by convention,
 	# followed by the output of the command "list" that we gave),
 	# we don't need to do anything in this case.
-	if ($ref eq "HEAD") {
+	if ($ref eq 'HEAD') {
 		return;
 	}
 
@@ -819,15 +818,15 @@ sub mw_import_ref {
 	}
 
 	my $n = 0;
-	if ($fetch_strategy eq "by_rev") {
+	if ($fetch_strategy eq 'by_rev') {
 		print STDERR "Fetching & writing export data by revs...\n";
 		$n = mw_import_ref_by_revs($fetch_from);
-	} elsif ($fetch_strategy eq "by_page") {
+	} elsif ($fetch_strategy eq 'by_page') {
 		print STDERR "Fetching & writing export data by pages...\n";
 		$n = mw_import_ref_by_pages($fetch_from);
 	} else {
-		print STDERR "fatal: invalid fetch strategy \"$fetch_strategy\".\n";
-		print STDERR "Check your configuration variables remote.$remotename.fetchStrategy and mediawiki.fetchStrategy\n";
+		print STDERR qq(fatal: invalid fetch strategy "${fetch_strategy}".\n);
+		print STDERR "Check your configuration variables remote.${remotename}.fetchStrategy and mediawiki.fetchStrategy\n";
 		exit 1;
 	}
 
@@ -901,7 +900,7 @@ sub mw_import_revids {
 		}
 
 		if (!defined($result->{query}->{pages})) {
-			die "Invalid revision $pagerevid.\n";
+			die "Invalid revision ${pagerevid}.\n";
 		}
 
 		my @result_pages = values(%{$result->{query}->{pages}});
@@ -911,8 +910,8 @@ sub mw_import_revids {
 		my $page_title = $result_page->{title};
 
 		if (!exists($pages->{$page_title})) {
-			print STDERR "$n/", scalar(@$revision_ids),
-				": Skipping revision #$rev->{revid} of $page_title\n";
+			print STDERR "${n}/", scalar(@$revision_ids),
+				": Skipping revision #$rev->{revid} of ${page_title}\n";
 			next;
 		}
 
@@ -937,14 +936,14 @@ sub mw_import_revids {
 		my %mediafile;
 		if ($namespace) {
 			my $id = get_mw_namespace_id($namespace);
-			if ($id && $id == get_mw_namespace_id("File")) {
+			if ($id && $id == get_mw_namespace_id('File')) {
 				%mediafile = get_mw_mediafile_for_page_revision($filename, $rev->{timestamp});
 			}
 		}
 		# If this is a revision of the media page for new version
 		# of a file do one common commit for both file and media page.
 		# Else do commit only for that page.
-		print STDERR "$n/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
+		print STDERR "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
 		import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
 	}
 
@@ -952,9 +951,9 @@ sub mw_import_revids {
 }
 
 sub error_non_fast_forward {
-	my $advice = run_git("config --bool advice.pushNonFastForward");
+	my $advice = run_git('config --bool advice.pushNonFastForward');
 	chomp($advice);
-	if ($advice ne "false") {
+	if ($advice ne 'false') {
 		# Native git-push would show this after the summary.
 		# We can't ask it to display it cleanly, so print it
 		# ourselves before.
@@ -962,7 +961,7 @@ sub error_non_fast_forward {
 		print STDERR "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
 		print STDERR "'Note about fast-forwards' section of 'git push --help' for details.\n";
 	}
-	print STDOUT "error $_[0] \"non-fast-forward\"\n";
+	print STDOUT qq(error $_[0] "non-fast-forward"\n);
 	return 0;
 }
 
@@ -973,10 +972,10 @@ sub mw_upload_file {
 	my $file_deleted = shift;
 	my $summary = shift;
 	my $newrevid;
-	my $path = "File:" . $complete_file_name;
+	my $path = "File:${complete_file_name}";
 	my %hashFiles = get_allowed_file_extensions();
 	if (!exists($hashFiles{$extension})) {
-		print STDERR "$complete_file_name is not a permitted file on this wiki.\n";
+		print STDERR "${complete_file_name} is not a permitted file on this wiki.\n";
 		print STDERR "Check the configuration of file uploads in your mediawiki.\n";
 		return $newrevid;
 	}
@@ -996,11 +995,11 @@ sub mw_upload_file {
 		}
 	} else {
 		# Don't let perl try to interpret file content as UTF-8 => use "raw"
-		my $content = run_git("cat-file blob $new_sha1", "raw");
+		my $content = run_git("cat-file blob ${new_sha1}", 'raw');
 		if ($content ne "") {
 			mw_connect_maybe();
 			$mediawiki->{config}->{upload_url} =
-				"$url/index.php/Special:Upload";
+				"${url}/index.php/Special:Upload";
 			$mediawiki->edit({
 				action => 'upload',
 				filename => $complete_file_name,
@@ -1015,9 +1014,9 @@ sub mw_upload_file {
 				 . $mediawiki->{error}->{details} . "\n";
 			my $last_file_page = $mediawiki->get_page({title => $path});
 			$newrevid = $last_file_page->{revid};
-			print STDERR "Pushed file: $new_sha1 - $complete_file_name.\n";
+			print STDERR "Pushed file: ${new_sha1} - ${complete_file_name}.\n";
 		} else {
-			print STDERR "Empty file $complete_file_name not pushed.\n";
+			print STDERR "Empty file ${complete_file_name} not pushed.\n";
 		}
 	}
 	return $newrevid;
@@ -1052,11 +1051,11 @@ sub mw_push_file {
 	if (!defined($extension)) {
 		$extension = "";
 	}
-	if ($extension eq "mw") {
+	if ($extension eq 'mw') {
 		my $ns = get_mw_namespace_id_for_page($complete_file_name);
-		if ($ns && $ns == get_mw_namespace_id("File") && (!$export_media)) {
-			print STDERR "Ignoring media file related page: $complete_file_name\n";
-			return ($oldrevid, "ok");
+		if ($ns && $ns == get_mw_namespace_id('File') && (!$export_media)) {
+			print STDERR "Ignoring media file related page: ${complete_file_name}\n";
+			return ($oldrevid, 'ok');
 		}
 		my $file_content;
 		if ($page_deleted) {
@@ -1066,7 +1065,7 @@ sub mw_push_file {
 			# with this content instead:
 			$file_content = DELETED_CONTENT;
 		} else {
-			$file_content = run_git("cat-file blob $new_sha1");
+			$file_content = run_git("cat-file blob ${new_sha1}");
 		}
 
 		mw_connect_maybe();
@@ -1087,7 +1086,7 @@ sub mw_push_file {
 				    $mediawiki->{error}->{code} .
 				    ' from mediwiki: ' . $mediawiki->{error}->{details} .
 				    ".\n";
-				return ($oldrevid, "non-fast-forward");
+				return ($oldrevid, 'non-fast-forward');
 			} else {
 				# Other errors. Shouldn't happen => just die()
 				die 'Fatal: Error ' .
@@ -1096,21 +1095,21 @@ sub mw_push_file {
 			}
 		}
 		$newrevid = $result->{edit}->{newrevid};
-		print STDERR "Pushed file: $new_sha1 - $title\n";
+		print STDERR "Pushed file: ${new_sha1} - ${title}\n";
 	} elsif ($export_media) {
 		$newrevid = mw_upload_file($complete_file_name, $new_sha1,
 					   $extension, $page_deleted,
 					   $summary);
 	} else {
-		print STDERR "Ignoring media file $title\n";
+		print STDERR "Ignoring media file ${title}\n";
 	}
 	$newrevid = ($newrevid or $oldrevid);
-	return ($newrevid, "ok");
+	return ($newrevid, 'ok');
 }
 
 sub mw_push {
 	# multiple push statements can follow each other
-	my @refsspecs = (shift, get_more_refs("push"));
+	my @refsspecs = (shift, get_more_refs('push'));
 	my $pushed;
 	for my $refspec (@refsspecs) {
 		my ($force, $local, $remote) = $refspec =~ /^(\+)?([^:]*):([^:]*)$/
@@ -1120,12 +1119,12 @@ sub mw_push {
 		}
 		if ($local eq "") {
 			print STDERR "Cannot delete remote branch on a MediaWiki\n";
-			print STDOUT "error $remote cannot delete\n";
+			print STDOUT "error ${remote} cannot delete\n";
 			next;
 		}
-		if ($remote ne "refs/heads/master") {
+		if ($remote ne 'refs/heads/master') {
 			print STDERR "Only push to the branch 'master' is supported on a MediaWiki\n";
-			print STDOUT "error $remote only master allowed\n";
+			print STDOUT "error ${remote} only master allowed\n";
 			next;
 		}
 		if (mw_push_revision($local, $remote)) {
@@ -1156,9 +1155,10 @@ sub mw_push_revision {
 	my $mw_revision = $last_remote_revid;
 
 	# Get sha1 of commit pointed by local HEAD
-	my $HEAD_sha1 = run_git("rev-parse $local 2>/dev/null"); chomp($HEAD_sha1);
+	my $HEAD_sha1 = run_git("rev-parse ${local} 2>/dev/null");
+	chomp($HEAD_sha1);
 	# Get sha1 of commit pointed by remotes/$remotename/master
-	my $remoteorigin_sha1 = run_git("rev-parse refs/remotes/$remotename/master 2>/dev/null");
+	my $remoteorigin_sha1 = run_git("rev-parse refs/remotes/${remotename}/master 2>/dev/null");
 	chomp($remoteorigin_sha1);
 
 	if ($last_local_revid > 0 &&
@@ -1178,7 +1178,7 @@ sub mw_push_revision {
 		my $parsed_sha1 = $remoteorigin_sha1;
 		# Find a path from last MediaWiki commit to pushed commit
 		print STDERR "Computing path from local to remote ...\n";
-		my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents $local ^$parsed_sha1"));
+		my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents ${local} ^${parsed_sha1}"));
 		my %local_ancestry;
 		foreach my $line (@local_ancestry) {
 			if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
@@ -1186,7 +1186,7 @@ sub mw_push_revision {
 					$local_ancestry{$parent} = $child;
 				}
 			} elsif (!$line =~ /^([a-f0-9]+)/) {
-				die "Unexpected output from git rev-list: $line\n";
+				die "Unexpected output from git rev-list: ${line}\n";
 			}
 		}
 		while ($parsed_sha1 ne $HEAD_sha1) {
@@ -1202,7 +1202,7 @@ sub mw_push_revision {
 		# No remote mediawiki revision. Export the whole
 		# history (linearized with --first-parent)
 		print STDERR "Warning: no common ancestor, pushing complete history\n";
-		my $history = run_git("rev-list --first-parent --children $local");
+		my $history = run_git("rev-list --first-parent --children ${local}");
 		my @history = split(/\n/, $history);
 		@history = @history[1..$#history];
 		foreach my $line (reverse @history) {
@@ -1214,12 +1214,12 @@ sub mw_push_revision {
 	foreach my $commit_info_split (@commit_pairs) {
 		my $sha1_child = @{$commit_info_split}[0];
 		my $sha1_commit = @{$commit_info_split}[1];
-		my $diff_infos = run_git("diff-tree -r --raw -z $sha1_child $sha1_commit");
+		my $diff_infos = run_git("diff-tree -r --raw -z ${sha1_child} ${sha1_commit}");
 		# TODO: we could detect rename, and encode them with a #redirect on the wiki.
 		# TODO: for now, it's just a delete+add
 		my @diff_info_list = split(/\0/, $diff_infos);
 		# Keep the subject line of the commit message as mediawiki comment for the revision
-		my $commit_msg = run_git("log --no-walk --format=\"%s\" $sha1_commit");
+		my $commit_msg = run_git(qq(log --no-walk --format="%s" ${sha1_commit}));
 		chomp($commit_msg);
 		# Push every blob
 		while (@diff_info_list) {
@@ -1231,7 +1231,7 @@ sub mw_push_revision {
 			my $info = shift(@diff_info_list);
 			my $file = shift(@diff_info_list);
 			($mw_revision, $status) = mw_push_file($info, $file, $commit_msg, $mw_revision);
-			if ($status eq "non-fast-forward") {
+			if ($status eq 'non-fast-forward') {
 				# we may already have sent part of the
 				# commit to MediaWiki, but it's too
 				# late to cancel it. Stop the push in
@@ -1239,17 +1239,17 @@ sub mw_push_revision {
 				# accurate error message.
 				return error_non_fast_forward($remote);
 			}
-			if ($status ne "ok") {
+			if ($status ne 'ok') {
 				die("Unknown error from mw_push_file()\n");
 			}
 		}
 		unless ($dumb_push) {
-			run_git("notes --ref=$remotename/mediawiki add -f -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
-			run_git("update-ref -m \"Git-MediaWiki push\" refs/mediawiki/$remotename/master $sha1_commit $sha1_child");
+			run_git(qq(notes --ref=${remotename}/mediawiki add -f -m "mediawiki_revision: ${mw_revision}" ${sha1_commit}));
+			run_git(qq(update-ref -m "Git-MediaWiki push" refs/mediawiki/${remotename}/master ${sha1_commit} ${sha1_child}));
 		}
 	}
 
-	print STDOUT "ok $remote\n";
+	print STDOUT "ok ${remote}\n";
 	return 1;
 }
 
@@ -1285,8 +1285,7 @@ sub get_mw_namespace_id {
 		# Look at configuration file, if the record for that namespace is
 		# already cached. Namespaces are stored in form:
 		# "Name_of_namespace:Id_namespace", ex.: "File:6".
-		my @temp = split(/\n/, run_git("config --get-all remote."
-						. $remotename .".namespaceCache"));
+		my @temp = split(/\n/, run_git("config --get-all remote.${remotename}.namespaceCache"));
 		chomp(@temp);
 		foreach my $ns (@temp) {
 			my ($n, $id) = split(/:/, $ns);
@@ -1300,7 +1299,7 @@ sub get_mw_namespace_id {
 	}
 
 	if (!exists $namespace_id{$name}) {
-		print STDERR "Namespace $name not found in cache, querying the wiki ...\n";
+		print STDERR "Namespace ${name} not found in cache, querying the wiki ...\n";
 		# NS not found => get namespace id from MW and store it in
 	        # configuration file.
 	        my $query = {
@@ -1325,7 +1324,7 @@ sub get_mw_namespace_id {
 	my $id;
 
 	unless (defined $ns) {
-		print STDERR "No such namespace $name on MediaWiki.\n";
+		print STDERR "No such namespace ${name} on MediaWiki.\n";
 		$ns = {is_namespace => 0};
 		$namespace_id{$name} = $ns;
 	}
@@ -1339,8 +1338,7 @@ sub get_mw_namespace_id {
 
 	# Store explicitely requested namespaces on disk
 	if (!exists $cached_mw_namespace_id{$name}) {
-		run_git("config --add remote.". $remotename
-			.".namespaceCache \"". $name .":". $store_id ."\"");
+		run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));
 		$cached_mw_namespace_id{$name} = 1;
 	}
 	return $id;
-- 
1.7.9.5

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

* [PATCH v3 23/28] git-remote-mediawiki: Brace file handles for print for more clarity
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (21 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 24/28] git-remote-mediawiki: Replace "unless" statements with negated "if" statements Célestin Matte
                   ` (5 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

This follows the following rule:
InputOutput::RequireBracedFileHandleWithPrint (Severity: 1)
    The `print' and `printf' functions have a unique syntax that supports an
    optional file handle argument. Conway suggests wrapping this argument in
    braces to make it visually stand out from the other arguments. When you
    put braces around any of the special package-level file handles like
    `STDOUT', `STDERR', and `DATA', you must the `'*'' sigil or else it
    won't compile under `use strict 'subs''.

      print $FH   "Mary had a little lamb\n";  #not ok
      print {$FH} "Mary had a little lamb\n";  #ok

      print   STDERR   $foo, $bar, $baz;  #not ok
      print  {STDERR}  $foo, $bar, $baz;  #won't compile under 'strict'
      print {*STDERR}  $foo, $bar, $baz;  #perfect!

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |  196 +++++++++++++--------------
 1 file changed, 98 insertions(+), 98 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index efc376a..1cda460 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -173,7 +173,7 @@ sub parse_command {
 	} elsif ($cmd[0] eq 'push') {
 		mw_push($cmd[1]);
 	} else {
-		print STDERR "Unknown command. Aborting...\n";
+		print {*STDERR} "Unknown command. Aborting...\n";
 		return 0;
 	}
 	return 1;
@@ -200,10 +200,10 @@ sub mw_connect_maybe {
 			       lgdomain => $wiki_domain};
 		if ($mediawiki->login($request)) {
 			Git::credential \%credential, 'approve';
-			print STDERR qq(Logged in mediawiki user "$credential{username}".\n);
+			print {*STDERR} qq(Logged in mediawiki user "$credential{username}".\n);
 		} else {
-			print STDERR qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);
-			print STDERR '  (error ' .
+			print {*STDERR} qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);
+			print {*STDERR} '  (error ' .
 				$mediawiki->{error}->{code} . ': ' .
 				$mediawiki->{error}->{details} . ")\n";
 			Git::credential \%credential, 'reject';
@@ -268,9 +268,9 @@ sub get_mw_all_pages {
 		aplimit => 'max'
 	});
 	if (!defined($mw_pages)) {
-		print STDERR "fatal: could not get the list of wiki pages.\n";
-		print STDERR "fatal: '${url}' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '${url}/api.php' is a valid page.\n";
+		print {*STDERR} "fatal: could not get the list of wiki pages.\n";
+		print {*STDERR} "fatal: '${url}' does not appear to be a mediawiki\n";
+		print {*STDERR} "fatal: make sure '${url}/api.php' is a valid page.\n";
 		exit 1;
 	}
 	foreach my $page (@{$mw_pages}) {
@@ -295,14 +295,14 @@ sub get_mw_first_pages {
 		titles => $titles,
 	});
 	if (!defined($mw_pages)) {
-		print STDERR "fatal: could not query the list of wiki pages.\n";
-		print STDERR "fatal: '${url}' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '${url}/api.php' is a valid page.\n";
+		print {*STDERR} "fatal: could not query the list of wiki pages.\n";
+		print {*STDERR} "fatal: '${url}' does not appear to be a mediawiki\n";
+		print {*STDERR} "fatal: make sure '${url}/api.php' is a valid page.\n";
 		exit 1;
 	}
 	while (my ($id, $page) = each(%{$mw_pages->{query}->{pages}})) {
 		if ($id < 0) {
-			print STDERR "Warning: page $page->{title} not found on wiki\n";
+			print {*STDERR} "Warning: page $page->{title} not found on wiki\n";
 		} else {
 			$pages->{$page->{title}} = $page;
 		}
@@ -314,7 +314,7 @@ sub get_mw_first_pages {
 sub get_mw_pages {
 	mw_connect_maybe();
 
-	print STDERR "Listing pages on remote wiki...\n";
+	print {*STDERR} "Listing pages on remote wiki...\n";
 
 	my %pages; # hash on page titles to avoid duplicates
 	my $user_defined;
@@ -332,14 +332,14 @@ sub get_mw_pages {
 		get_mw_all_pages(\%pages);
 	}
 	if ($import_media) {
-		print STDERR "Getting media files for selected pages...\n";
+		print {*STDERR} "Getting media files for selected pages...\n";
 		if ($user_defined) {
 			get_linked_mediafiles(\%pages);
 		} else {
 			get_all_mediafiles(\%pages);
 		}
 	}
-	print STDERR (scalar keys %pages) . " pages found.\n";
+	print {*STDERR} (scalar keys %pages) . " pages found.\n";
 	return %pages;
 }
 
@@ -372,9 +372,9 @@ sub get_all_mediafiles {
 		aplimit => 'max'
 	});
 	if (!defined($mw_pages)) {
-		print STDERR "fatal: could not get the list of pages for media files.\n";
-		print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
+		print {*STDERR} "fatal: could not get the list of pages for media files.\n";
+		print {*STDERR} "fatal: '$url' does not appear to be a mediawiki\n";
+		print {*STDERR} "fatal: make sure '$url/api.php' is a valid page.\n";
 		exit 1;
 	}
 	foreach my $page (@{$mw_pages}) {
@@ -461,7 +461,7 @@ sub get_mw_mediafile_for_page_revision {
 		$mediafile{timestamp} = $fileinfo->{timestamp};
 		# Mediawiki::API's download function doesn't support https URLs
 		# and can't download old versions of files.
-		print STDERR "\tDownloading file $mediafile{title}, version $mediafile{timestamp}\n";
+		print {*STDERR} "\tDownloading file $mediafile{title}, version $mediafile{timestamp}\n";
 		$mediafile{content} = download_mw_mediafile($fileinfo->{url});
 	}
 	return %mediafile;
@@ -474,9 +474,9 @@ sub download_mw_mediafile {
 	if ($response->code == 200) {
 		return $response->decoded_content;
 	} else {
-		print STDERR "Error downloading mediafile from :\n";
-		print STDERR "URL: ${download_url}\n";
-		print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";
+		print {*STDERR} "Error downloading mediafile from :\n";
+		print {*STDERR} "URL: ${download_url}\n";
+		print {*STDERR} 'Server response: ' . $response->code . q{ } . $response->message . "\n";
 		exit 1;
 	}
 }
@@ -488,13 +488,13 @@ sub get_last_local_revision {
 
 	my $lastrevision_number;
 	if (!(defined($note_info[0]) && $note_info[0] eq 'mediawiki_revision:')) {
-		print STDERR 'No previous mediawiki revision found';
+		print {*STDERR} 'No previous mediawiki revision found';
 		$lastrevision_number = 0;
 	} else {
 		# Notes are formatted : mediawiki_revision: #number
 		$lastrevision_number = $note_info[1];
 		chomp($lastrevision_number);
-		print STDERR "Last local mediawiki revision found is ${lastrevision_number}";
+		print {*STDERR} "Last local mediawiki revision found is ${lastrevision_number}";
 	}
 	return $lastrevision_number;
 }
@@ -527,7 +527,7 @@ sub get_last_remote_revision {
 
 	my $max_rev_num = 0;
 
-	print STDERR "Getting last revision id on tracked pages...\n";
+	print {*STDERR} "Getting last revision id on tracked pages...\n";
 
 	foreach my $page (@pages) {
 		my $id = $page->{pageid};
@@ -548,7 +548,7 @@ sub get_last_remote_revision {
 		$max_rev_num = ($lastrev->{revid} > $max_rev_num ? $lastrev->{revid} : $max_rev_num);
 	}
 
-	print STDERR "Last remote revision found is $max_rev_num.\n";
+	print {*STDERR} "Last remote revision found is $max_rev_num.\n";
 	return $max_rev_num;
 }
 
@@ -601,7 +601,7 @@ sub mediawiki_smudge_filename {
 
 sub literal_data {
 	my ($content) = @_;
-	print STDOUT 'data ', bytes::length($content), "\n", $content;
+	print {*STDOUT} 'data ', bytes::length($content), "\n", $content;
 	return;
 }
 
@@ -620,26 +620,26 @@ sub mw_capabilities {
 	# Revisions are imported to the private namespace
 	# refs/mediawiki/$remotename/ by the helper and fetched into
 	# refs/remotes/$remotename later by fetch.
-	print STDOUT "refspec refs/heads/*:refs/mediawiki/${remotename}/*\n";
-	print STDOUT "import\n";
-	print STDOUT "list\n";
-	print STDOUT "push\n";
-	print STDOUT "\n";
+	print {*STDOUT} "refspec refs/heads/*:refs/mediawiki/${remotename}/*\n";
+	print {*STDOUT} "import\n";
+	print {*STDOUT} "list\n";
+	print {*STDOUT} "push\n";
+	print {*STDOUT} "\n";
 	return;
 }
 
 sub mw_list {
 	# MediaWiki do not have branches, we consider one branch arbitrarily
 	# called master, and HEAD pointing to it.
-	print STDOUT "? refs/heads/master\n";
-	print STDOUT "\@refs/heads/master HEAD\n";
-	print STDOUT "\n";
+	print {*STDOUT} "? refs/heads/master\n";
+	print {*STDOUT} "\@refs/heads/master HEAD\n";
+	print {*STDOUT} "\n";
 	return;
 }
 
 sub mw_option {
-	print STDERR "remote-helper command 'option $_[0]' not yet implemented\n";
-	print STDOUT "unsupported\n";
+	print {*STDERR} "remote-helper command 'option $_[0]' not yet implemented\n";
+	print {*STDOUT} "unsupported\n";
 	return;
 }
 
@@ -675,11 +675,11 @@ sub fetch_mw_revisions_for_page {
 		$query->{rvstartid} = $result->{'query-continue'}->{revisions}->{rvstartid};
 	}
 	if ($shallow_import && @page_revs) {
-		print STDERR "  Found 1 revision (shallow import).\n";
+		print {*STDERR} "  Found 1 revision (shallow import).\n";
 		@page_revs = sort {$b->{revid} <=> $a->{revid}} (@page_revs);
 		return $page_revs[0];
 	}
-	print STDERR "  Found ${revnum} revision(s).\n";
+	print {*STDERR} "  Found ${revnum} revision(s).\n";
 	return @page_revs;
 }
 
@@ -691,7 +691,7 @@ sub fetch_mw_revisions {
 	my $n = 1;
 	foreach my $page (@pages) {
 		my $id = $page->{pageid};
-		print STDERR "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";
+		print {*STDERR} "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";
 		$n++;
 		my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
 		@revisions = (@page_revs, @revisions);
@@ -725,42 +725,42 @@ sub import_file_revision {
 	my $author = $commit{author};
 	my $date = $commit{date};
 
-	print STDOUT "commit refs/mediawiki/${remotename}/master\n";
-	print STDOUT "mark :${n}\n";
-	print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
+	print {*STDOUT} "commit refs/mediawiki/${remotename}/master\n";
+	print {*STDOUT} "mark :${n}\n";
+	print {*STDOUT} "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
 	literal_data($comment);
 
 	# If it's not a clone, we need to know where to start from
 	if (!$full_import && $n == 1) {
-		print STDOUT "from refs/mediawiki/${remotename}/master^0\n";
+		print {*STDOUT} "from refs/mediawiki/${remotename}/master^0\n";
 	}
 	if ($content ne DELETED_CONTENT) {
-		print STDOUT 'M 644 inline ' .
+		print {*STDOUT} 'M 644 inline ' .
 		    fe_escape_path("${title}.mw") . "\n";
 		literal_data($content);
 		if (%mediafile) {
-			print STDOUT 'M 644 inline '
+			print {*STDOUT} 'M 644 inline '
 			    . fe_escape_path($mediafile{title}) . "\n";
 			literal_data_raw($mediafile{content});
 		}
-		print STDOUT "\n\n";
+		print {*STDOUT} "\n\n";
 	} else {
-		print STDOUT 'D ' . fe_escape_path("${title}.mw") . "\n";
+		print {*STDOUT} 'D ' . fe_escape_path("${title}.mw") . "\n";
 	}
 
 	# mediawiki revision number in the git note
 	if ($full_import && $n == 1) {
-		print STDOUT "reset refs/notes/${remotename}/mediawiki\n";
+		print {*STDOUT} "reset refs/notes/${remotename}/mediawiki\n";
 	}
-	print STDOUT "commit refs/notes/${remotename}/mediawiki\n";
-	print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
+	print {*STDOUT} "commit refs/notes/${remotename}/mediawiki\n";
+	print {*STDOUT} "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
 	literal_data('Note added by git-mediawiki during import');
 	if (!$full_import && $n == 1) {
-		print STDOUT "from refs/notes/${remotename}/mediawiki^0\n";
+		print {*STDOUT} "from refs/notes/${remotename}/mediawiki^0\n";
 	}
-	print STDOUT "N inline :${n}\n";
+	print {*STDOUT} "N inline :${n}\n";
 	literal_data("mediawiki_revision: $commit{mw_revision}");
-	print STDOUT "\n\n";
+	print {*STDOUT} "\n\n";
 	return;
 }
 
@@ -791,7 +791,7 @@ sub mw_import {
 	foreach my $ref (@refs) {
 		mw_import_ref($ref);
 	}
-	print STDOUT "done\n";
+	print {*STDOUT} "done\n";
 	return;
 }
 
@@ -808,30 +808,30 @@ sub mw_import_ref {
 
 	mw_connect_maybe();
 
-	print STDERR "Searching revisions...\n";
+	print {*STDERR} "Searching revisions...\n";
 	my $last_local = get_last_local_revision();
 	my $fetch_from = $last_local + 1;
 	if ($fetch_from == 1) {
-		print STDERR ", fetching from beginning.\n";
+		print {*STDERR} ", fetching from beginning.\n";
 	} else {
-		print STDERR ", fetching from here.\n";
+		print {*STDERR} ", fetching from here.\n";
 	}
 
 	my $n = 0;
 	if ($fetch_strategy eq 'by_rev') {
-		print STDERR "Fetching & writing export data by revs...\n";
+		print {*STDERR} "Fetching & writing export data by revs...\n";
 		$n = mw_import_ref_by_revs($fetch_from);
 	} elsif ($fetch_strategy eq 'by_page') {
-		print STDERR "Fetching & writing export data by pages...\n";
+		print {*STDERR} "Fetching & writing export data by pages...\n";
 		$n = mw_import_ref_by_pages($fetch_from);
 	} else {
-		print STDERR qq(fatal: invalid fetch strategy "${fetch_strategy}".\n);
-		print STDERR "Check your configuration variables remote.${remotename}.fetchStrategy and mediawiki.fetchStrategy\n";
+		print {*STDERR} qq(fatal: invalid fetch strategy "${fetch_strategy}".\n);
+		print {*STDERR} "Check your configuration variables remote.${remotename}.fetchStrategy and mediawiki.fetchStrategy\n";
 		exit 1;
 	}
 
 	if ($fetch_from == 1 && $n == 0) {
-		print STDERR "You appear to have cloned an empty MediaWiki.\n";
+		print {*STDERR} "You appear to have cloned an empty MediaWiki.\n";
 		# Something has to be done remote-helper side. If nothing is done, an error is
 		# thrown saying that HEAD is referring to unknown object 0000000000000000000
 		# and the clone fails.
@@ -910,7 +910,7 @@ sub mw_import_revids {
 		my $page_title = $result_page->{title};
 
 		if (!exists($pages->{$page_title})) {
-			print STDERR "${n}/", scalar(@$revision_ids),
+			print {*STDERR} "${n}/", scalar(@$revision_ids),
 				": Skipping revision #$rev->{revid} of ${page_title}\n";
 			next;
 		}
@@ -943,7 +943,7 @@ sub mw_import_revids {
 		# If this is a revision of the media page for new version
 		# of a file do one common commit for both file and media page.
 		# Else do commit only for that page.
-		print STDERR "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
+		print {*STDERR} "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
 		import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
 	}
 
@@ -957,11 +957,11 @@ sub error_non_fast_forward {
 		# Native git-push would show this after the summary.
 		# We can't ask it to display it cleanly, so print it
 		# ourselves before.
-		print STDERR "To prevent you from losing history, non-fast-forward updates were rejected\n";
-		print STDERR "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
-		print STDERR "'Note about fast-forwards' section of 'git push --help' for details.\n";
+		print {*STDERR} "To prevent you from losing history, non-fast-forward updates were rejected\n";
+		print {*STDERR} "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
+		print {*STDERR} "'Note about fast-forwards' section of 'git push --help' for details.\n";
 	}
-	print STDOUT qq(error $_[0] "non-fast-forward"\n);
+	print {*STDOUT} qq(error $_[0] "non-fast-forward"\n);
 	return 0;
 }
 
@@ -975,8 +975,8 @@ sub mw_upload_file {
 	my $path = "File:${complete_file_name}";
 	my %hashFiles = get_allowed_file_extensions();
 	if (!exists($hashFiles{$extension})) {
-		print STDERR "${complete_file_name} is not a permitted file on this wiki.\n";
-		print STDERR "Check the configuration of file uploads in your mediawiki.\n";
+		print {*STDERR} "${complete_file_name} is not a permitted file on this wiki.\n";
+		print {*STDERR} "Check the configuration of file uploads in your mediawiki.\n";
 		return $newrevid;
 	}
 	# Deleting and uploading a file requires a priviledged user
@@ -988,9 +988,9 @@ sub mw_upload_file {
 			reason => $summary
 		};
 		if (!$mediawiki->edit($query)) {
-			print STDERR "Failed to delete file on remote wiki\n";
-			print STDERR "Check your permissions on the remote site. Error code:\n";
-			print STDERR $mediawiki->{error}->{code} . ':' . $mediawiki->{error}->{details};
+			print {*STDERR} "Failed to delete file on remote wiki\n";
+			print {*STDERR} "Check your permissions on the remote site. Error code:\n";
+			print {*STDERR} $mediawiki->{error}->{code} . ':' . $mediawiki->{error}->{details};
 			exit 1;
 		}
 	} else {
@@ -1014,9 +1014,9 @@ sub mw_upload_file {
 				 . $mediawiki->{error}->{details} . "\n";
 			my $last_file_page = $mediawiki->get_page({title => $path});
 			$newrevid = $last_file_page->{revid};
-			print STDERR "Pushed file: ${new_sha1} - ${complete_file_name}.\n";
+			print {*STDERR} "Pushed file: ${new_sha1} - ${complete_file_name}.\n";
 		} else {
-			print STDERR "Empty file ${complete_file_name} not pushed.\n";
+			print {*STDERR} "Empty file ${complete_file_name} not pushed.\n";
 		}
 	}
 	return $newrevid;
@@ -1054,7 +1054,7 @@ sub mw_push_file {
 	if ($extension eq 'mw') {
 		my $ns = get_mw_namespace_id_for_page($complete_file_name);
 		if ($ns && $ns == get_mw_namespace_id('File') && (!$export_media)) {
-			print STDERR "Ignoring media file related page: ${complete_file_name}\n";
+			print {*STDERR} "Ignoring media file related page: ${complete_file_name}\n";
 			return ($oldrevid, 'ok');
 		}
 		my $file_content;
@@ -1082,7 +1082,7 @@ sub mw_push_file {
 		if (!$result) {
 			if ($mediawiki->{error}->{code} == 3) {
 				# edit conflicts, considered as non-fast-forward
-				print STDERR 'Warning: Error ' .
+				print {*STDERR} 'Warning: Error ' .
 				    $mediawiki->{error}->{code} .
 				    ' from mediwiki: ' . $mediawiki->{error}->{details} .
 				    ".\n";
@@ -1095,13 +1095,13 @@ sub mw_push_file {
 			}
 		}
 		$newrevid = $result->{edit}->{newrevid};
-		print STDERR "Pushed file: ${new_sha1} - ${title}\n";
+		print {*STDERR} "Pushed file: ${new_sha1} - ${title}\n";
 	} elsif ($export_media) {
 		$newrevid = mw_upload_file($complete_file_name, $new_sha1,
 					   $extension, $page_deleted,
 					   $summary);
 	} else {
-		print STDERR "Ignoring media file ${title}\n";
+		print {*STDERR} "Ignoring media file ${title}\n";
 	}
 	$newrevid = ($newrevid or $oldrevid);
 	return ($newrevid, 'ok');
@@ -1115,16 +1115,16 @@ sub mw_push {
 		my ($force, $local, $remote) = $refspec =~ /^(\+)?([^:]*):([^:]*)$/
 		    or die("Invalid refspec for push. Expected <src>:<dst> or +<src>:<dst>\n");
 		if ($force) {
-			print STDERR "Warning: forced push not allowed on a MediaWiki.\n";
+			print {*STDERR} "Warning: forced push not allowed on a MediaWiki.\n";
 		}
 		if ($local eq "") {
-			print STDERR "Cannot delete remote branch on a MediaWiki\n";
-			print STDOUT "error ${remote} cannot delete\n";
+			print {*STDERR} "Cannot delete remote branch on a MediaWiki\n";
+			print {*STDOUT} "error ${remote} cannot delete\n";
 			next;
 		}
 		if ($remote ne 'refs/heads/master') {
-			print STDERR "Only push to the branch 'master' is supported on a MediaWiki\n";
-			print STDOUT "error ${remote} only master allowed\n";
+			print {*STDERR} "Only push to the branch 'master' is supported on a MediaWiki\n";
+			print {*STDOUT} "error ${remote} only master allowed\n";
 			next;
 		}
 		if (mw_push_revision($local, $remote)) {
@@ -1133,15 +1133,15 @@ sub mw_push {
 	}
 
 	# Notify Git that the push is done
-	print STDOUT "\n";
+	print {*STDOUT} "\n";
 
 	if ($pushed && $dumb_push) {
-		print STDERR "Just pushed some revisions to MediaWiki.\n";
-		print STDERR "The pushed revisions now have to be re-imported, and your current branch\n";
-		print STDERR "needs to be updated with these re-imported commits. You can do this with\n";
-		print STDERR "\n";
-		print STDERR "  git pull --rebase\n";
-		print STDERR "\n";
+		print {*STDERR} "Just pushed some revisions to MediaWiki.\n";
+		print {*STDERR} "The pushed revisions now have to be re-imported, and your current branch\n";
+		print {*STDERR} "needs to be updated with these re-imported commits. You can do this with\n";
+		print {*STDERR} "\n";
+		print {*STDERR} "  git pull --rebase\n";
+		print {*STDERR} "\n";
 	}
 	return;
 }
@@ -1150,7 +1150,7 @@ sub mw_push_revision {
 	my $local = shift;
 	my $remote = shift; # actually, this has to be "refs/heads/master" at this point.
 	my $last_local_revid = get_last_local_revision();
-	print STDERR ".\n"; # Finish sentence started by get_last_local_revision()
+	print {*STDERR} ".\n"; # Finish sentence started by get_last_local_revision()
 	my $last_remote_revid = get_last_remote_revision();
 	my $mw_revision = $last_remote_revid;
 
@@ -1177,7 +1177,7 @@ sub mw_push_revision {
 	if ($last_local_revid > 0) {
 		my $parsed_sha1 = $remoteorigin_sha1;
 		# Find a path from last MediaWiki commit to pushed commit
-		print STDERR "Computing path from local to remote ...\n";
+		print {*STDERR} "Computing path from local to remote ...\n";
 		my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents ${local} ^${parsed_sha1}"));
 		my %local_ancestry;
 		foreach my $line (@local_ancestry) {
@@ -1192,7 +1192,7 @@ sub mw_push_revision {
 		while ($parsed_sha1 ne $HEAD_sha1) {
 			my $child = $local_ancestry{$parsed_sha1};
 			if (!$child) {
-				printf STDERR "Cannot find a path in history from remote commit to last commit\n";
+				print {*STDERR} "Cannot find a path in history from remote commit to last commit\n";
 				return error_non_fast_forward($remote);
 			}
 			push(@commit_pairs, [$parsed_sha1, $child]);
@@ -1201,7 +1201,7 @@ sub mw_push_revision {
 	} else {
 		# No remote mediawiki revision. Export the whole
 		# history (linearized with --first-parent)
-		print STDERR "Warning: no common ancestor, pushing complete history\n";
+		print {*STDERR} "Warning: no common ancestor, pushing complete history\n";
 		my $history = run_git("rev-list --first-parent --children ${local}");
 		my @history = split(/\n/, $history);
 		@history = @history[1..$#history];
@@ -1249,7 +1249,7 @@ sub mw_push_revision {
 		}
 	}
 
-	print STDOUT "ok ${remote}\n";
+	print {*STDOUT} "ok ${remote}\n";
 	return 1;
 }
 
@@ -1299,7 +1299,7 @@ sub get_mw_namespace_id {
 	}
 
 	if (!exists $namespace_id{$name}) {
-		print STDERR "Namespace ${name} not found in cache, querying the wiki ...\n";
+		print {*STDERR} "Namespace ${name} not found in cache, querying the wiki ...\n";
 		# NS not found => get namespace id from MW and store it in
 	        # configuration file.
 	        my $query = {
@@ -1324,7 +1324,7 @@ sub get_mw_namespace_id {
 	my $id;
 
 	unless (defined $ns) {
-		print STDERR "No such namespace ${name} on MediaWiki.\n";
+		print {*STDERR} "No such namespace ${name} on MediaWiki.\n";
 		$ns = {is_namespace => 0};
 		$namespace_id{$name} = $ns;
 	}
-- 
1.7.9.5

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

* [PATCH v3 24/28] git-remote-mediawiki: Replace "unless" statements with negated "if" statements
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (22 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 23/28] git-remote-mediawiki: Brace file handles for print for more clarity Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 25/28] git-remote-mediawiki: Don't use quotes for empty strings Célestin Matte
                   ` (4 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 1cda460..bfb8a96 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -86,11 +86,11 @@ $shallow_import = ($shallow_import eq 'true');
 # - by_rev: perform one query per new revision on the remote wiki
 # - by_page: query each tracked page for new revision
 my $fetch_strategy = run_git("config --get remote.${remotename}.fetchStrategy");
-unless ($fetch_strategy) {
+if (!$fetch_strategy) {
 	$fetch_strategy = run_git('config --get mediawiki.fetchStrategy');
 }
 chomp($fetch_strategy);
-unless ($fetch_strategy) {
+if (!$fetch_strategy) {
 	$fetch_strategy = 'by_page';
 }
 
@@ -112,7 +112,7 @@ my %basetimestamps;
 # deterministic, this means everybody gets the same sha1 for each
 # MediaWiki revision.
 my $dumb_push = run_git("config --get --bool remote.${remotename}.dumbPush");
-unless ($dumb_push) {
+if (!$dumb_push) {
 	$dumb_push = run_git('config --get --bool mediawiki.dumbPush');
 }
 chomp($dumb_push);
@@ -671,7 +671,7 @@ sub fetch_mw_revisions_for_page {
 			push(@page_revs, $page_rev_ids);
 			$revnum++;
 		}
-		last unless $result->{'query-continue'};
+		last if (!$result->{'query-continue'});
 		$query->{rvstartid} = $result->{'query-continue'}->{revisions}->{rvstartid};
 	}
 	if ($shallow_import && @page_revs) {
@@ -1243,7 +1243,7 @@ sub mw_push_revision {
 				die("Unknown error from mw_push_file()\n");
 			}
 		}
-		unless ($dumb_push) {
+		if (!$dumb_push) {
 			run_git(qq(notes --ref=${remotename}/mediawiki add -f -m "mediawiki_revision: ${mw_revision}" ${sha1_commit}));
 			run_git(qq(update-ref -m "Git-MediaWiki push" refs/mediawiki/${remotename}/master ${sha1_commit} ${sha1_child}));
 		}
@@ -1323,7 +1323,7 @@ sub get_mw_namespace_id {
 	my $ns = $namespace_id{$name};
 	my $id;
 
-	unless (defined $ns) {
+	if (!defined $ns) {
 		print {*STDERR} "No such namespace ${name} on MediaWiki.\n";
 		$ns = {is_namespace => 0};
 		$namespace_id{$name} = $ns;
-- 
1.7.9.5

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

* [PATCH v3 25/28] git-remote-mediawiki: Don't use quotes for empty strings
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (23 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 24/28] git-remote-mediawiki: Replace "unless" statements with negated "if" statements Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 26/28] git-remote-mediawiki: Put non-trivial numeric values in constants Célestin Matte
                   ` (3 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Empty strings are replaced by an $EMPTY constant.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index bfb8a96..45a8804 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -40,6 +40,8 @@ use constant NULL_SHA1 => '0000000000000000000000000000000000000000';
 # Used on Git's side to reflect empty edit messages on the wiki
 use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
 
+use constant EMPTY => q{};
+
 if (@ARGV != 2) {
 	exit_error_usage();
 }
@@ -164,11 +166,11 @@ sub parse_command {
 		mw_list($cmd[1]);
 	} elsif ($cmd[0] eq 'import') {
 		die("Invalid arguments for import\n")
-		    if ($cmd[1] eq "" || defined($cmd[2]));
+		    if ($cmd[1] eq EMPTY || defined($cmd[2]));
 		mw_import($cmd[1]);
 	} elsif ($cmd[0] eq 'option') {
 		die("Too many arguments for option\n")
-		    if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
+		    if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY || defined($cmd[3]));
 		mw_option($cmd[1],$cmd[2]);
 	} elsif ($cmd[0] eq 'push') {
 		mw_push($cmd[1]);
@@ -559,7 +561,7 @@ sub mediawiki_clean {
 	# Mediawiki does not allow blank space at the end of a page and ends with a single \n.
 	# This function right trims a string and adds a \n at the end to follow this rule
 	$string =~ s/\s+$//;
-	if ($string eq "" && $page_created) {
+	if ($string eq EMPTY && $page_created) {
 		# Creating empty pages is forbidden.
 		$string = EMPTY_CONTENT;
 	}
@@ -570,7 +572,7 @@ sub mediawiki_clean {
 sub mediawiki_smudge {
 	my $string = shift;
 	if ($string eq EMPTY_CONTENT) {
-		$string = "";
+		$string = EMPTY;
 	}
 	# This \n is important. This is due to mediawiki's way to handle end of files.
 	return "${string}\n";
@@ -996,7 +998,7 @@ sub mw_upload_file {
 	} else {
 		# Don't let perl try to interpret file content as UTF-8 => use "raw"
 		my $content = run_git("cat-file blob ${new_sha1}", 'raw');
-		if ($content ne "") {
+		if ($content ne EMPTY) {
 			mw_connect_maybe();
 			$mediawiki->{config}->{upload_url} =
 				"${url}/index.php/Special:Upload";
@@ -1038,7 +1040,7 @@ sub mw_push_file {
 	my $newrevid;
 
 	if ($summary eq EMPTY_MESSAGE) {
-		$summary = '';
+		$summary = EMPTY;
 	}
 
 	my $new_sha1 = $diff_info_split[3];
@@ -1049,7 +1051,7 @@ sub mw_push_file {
 
 	my ($title, $extension) = $complete_file_name =~ /^(.*)\.([^\.]*)$/;
 	if (!defined($extension)) {
-		$extension = "";
+		$extension = EMPTY;
 	}
 	if ($extension eq 'mw') {
 		my $ns = get_mw_namespace_id_for_page($complete_file_name);
@@ -1117,7 +1119,7 @@ sub mw_push {
 		if ($force) {
 			print {*STDERR} "Warning: forced push not allowed on a MediaWiki.\n";
 		}
-		if ($local eq "") {
+		if ($local eq EMPTY) {
 			print {*STDERR} "Cannot delete remote branch on a MediaWiki\n";
 			print {*STDOUT} "error ${remote} cannot delete\n";
 			next;
-- 
1.7.9.5

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

* [PATCH v3 26/28] git-remote-mediawiki: Put non-trivial numeric values in constants.
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (24 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 25/28] git-remote-mediawiki: Don't use quotes for empty strings Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 27/28] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki") Célestin Matte
                   ` (2 subsequent siblings)
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Non-trivial numeric values (e.g., different from 0, 1 and 2) are placed in
constants at the top of the code to be easily modifiable and to make more sense

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 45a8804..c2b1afd 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -42,6 +42,16 @@ use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
 
 use constant EMPTY => q{};
 
+# Number of pages taken into account at once in submodule get_mw_page_list
+use constant SLICE_SIZE => 50;
+
+# Number of linked mediafile to get at once in get_linked_mediafiles
+# The query is split in small batches because of the MW API limit of
+# the number of links to be returned (500 links max).
+use constant BATCH_SIZE => 10;
+
+use constant HTTP_CODE_OK => 200;
+
 if (@ARGV != 2) {
 	exit_error_usage();
 }
@@ -227,13 +237,13 @@ sub get_mw_page_list {
 	my $pages = shift;
 	my @some_pages = @$page_list;
 	while (@some_pages) {
-		my $last_page = 50;
+		my $last_page = SLICE_SIZE;
 		if ($#some_pages < $last_page) {
 			$last_page = $#some_pages;
 		}
 		my @slice = @some_pages[0..$last_page];
 		get_mw_first_pages(\@slice, $pages);
-		@some_pages = @some_pages[51..$#some_pages];
+		@some_pages = @some_pages[(SLICE_SIZE + 1)..$#some_pages];
 	}
 	return;
 }
@@ -389,9 +399,7 @@ sub get_linked_mediafiles {
 	my $pages = shift;
 	my @titles = map { $_->{title} } values(%{$pages});
 
-	# The query is split in small batches because of the MW API limit of
-	# the number of links to be returned (500 links max).
-	my $batch = 10;
+	my $batch = BATCH_SIZE;
 	while (@titles) {
 		if ($#titles < $batch) {
 			$batch = $#titles;
@@ -473,7 +481,7 @@ sub download_mw_mediafile {
 	my $download_url = shift;
 
 	my $response = $mediawiki->{ua}->get($download_url);
-	if ($response->code == 200) {
+	if ($response->code == HTTP_CODE_OK) {
 		return $response->decoded_content;
 	} else {
 		print {*STDERR} "Error downloading mediafile from :\n";
-- 
1.7.9.5

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

* [PATCH v3 27/28] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki")
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (25 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 26/28] git-remote-mediawiki: Put non-trivial numeric values in constants Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-09 22:22 ` [PATCH v3 28/28] git-remote-mediawiki: Clearly rewrite double dereference Célestin Matte
  2013-06-10  1:09 ` [PATCH v3 00/28] Follow perlcritic's recommandations Eric Sunshine
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index c2b1afd..b0e540b 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1094,14 +1094,14 @@ sub mw_push_file {
 				# edit conflicts, considered as non-fast-forward
 				print {*STDERR} 'Warning: Error ' .
 				    $mediawiki->{error}->{code} .
-				    ' from mediwiki: ' . $mediawiki->{error}->{details} .
+				    ' from mediawiki: ' . $mediawiki->{error}->{details} .
 				    ".\n";
 				return ($oldrevid, 'non-fast-forward');
 			} else {
 				# Other errors. Shouldn't happen => just die()
 				die 'Fatal: Error ' .
 				    $mediawiki->{error}->{code} .
-				    ' from mediwiki: ' . $mediawiki->{error}->{details} . "\n";
+				    ' from mediawiki: ' . $mediawiki->{error}->{details} . "\n";
 			}
 		}
 		$newrevid = $result->{edit}->{newrevid};
-- 
1.7.9.5

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

* [PATCH v3 28/28] git-remote-mediawiki: Clearly rewrite double dereference
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (26 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 27/28] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki") Célestin Matte
@ 2013-06-09 22:22 ` Célestin Matte
  2013-06-10  1:09 ` [PATCH v3 00/28] Follow perlcritic's recommandations Eric Sunshine
  28 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-09 22:22 UTC (permalink / raw)
  To: git; +Cc: benoit.person, matthieu.moy, Célestin Matte

@$var structures are re-written in the following way: @{$var}
It makes them more readable.

Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index b0e540b..e0b2fd2 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -235,7 +235,7 @@ sub get_mw_tracked_pages {
 sub get_mw_page_list {
 	my $page_list = shift;
 	my $pages = shift;
-	my @some_pages = @$page_list;
+	my @some_pages = @{$page_list};
 	while (@some_pages) {
 		my $last_page = SLICE_SIZE;
 		if ($#some_pages < $last_page) {
@@ -885,7 +885,7 @@ sub mw_import_revids {
 	my $n_actual = 0;
 	my $last_timestamp = 0; # Placeholer in case $rev->timestamp is undefined
 
-	foreach my $pagerevid (@$revision_ids) {
+	foreach my $pagerevid (@{$revision_ids}) {
 	        # Count page even if we skip it, since we display
 		# $n/$total and $total includes skipped pages.
 		$n++;
@@ -920,7 +920,7 @@ sub mw_import_revids {
 		my $page_title = $result_page->{title};
 
 		if (!exists($pages->{$page_title})) {
-			print {*STDERR} "${n}/", scalar(@$revision_ids),
+			print {*STDERR} "${n}/", scalar(@{$revision_ids}),
 				": Skipping revision #$rev->{revid} of ${page_title}\n";
 			next;
 		}
@@ -953,7 +953,7 @@ sub mw_import_revids {
 		# If this is a revision of the media page for new version
 		# of a file do one common commit for both file and media page.
 		# Else do commit only for that page.
-		print {*STDERR} "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
+		print {*STDERR} "${n}/", scalar(@{$revision_ids}), ": Revision #$rev->{revid} of $commit{title}\n";
 		import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
 	}
 
-- 
1.7.9.5

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
@ 2013-06-10  0:50   ` Eric Sunshine
  2013-06-10 10:48     ` Célestin Matte
  2013-06-10  8:37   ` Matthieu Moy
  1 sibling, 1 reply; 48+ messages in thread
From: Eric Sunshine @ 2013-06-10  0:50 UTC (permalink / raw)
  To: Célestin Matte; +Cc: Git List, benoit.person, Matthieu Moy

On Sun, Jun 9, 2013 at 6:22 PM, Célestin Matte
<celestin.matte@ensimag.fr> wrote:
> - strings which don't need interpolation are single-quoted for more clarity and
> slight gain of performance
> - interpolation is preferred over concatenation in many cases, for more clarity
> - variables are always used with the ${} operator inside strings
> - strings including double-quotes are written with qq() so that the quotes do
> not have to be escaped
> ---
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index a66cef4..efc376a 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -200,10 +200,10 @@ sub mw_connect_maybe {
>                                lgdomain => $wiki_domain};
>                 if ($mediawiki->login($request)) {
>                         Git::credential \%credential, 'approve';
> -                       print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
> +                       print STDERR qq(Logged in mediawiki user "$credential{username}".\n);

Given this patch's intention to use ${} within strings, should this be
${credential{username}}?

(I don't have a preference, but it's a genuine question since it's not
clear if this was an oversight or intentional.)

>                 } else {
> -                       print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
> -                       print STDERR "  (error " .
> +                       print STDERR qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);

Ditto: ${credential{username}}

> +                       print STDERR '  (error ' .
>                                 $mediawiki->{error}->{code} . ': ' .
>                                 $mediawiki->{error}->{details} . ")\n";
>                         Git::credential \%credential, 'reject';
> @@ -347,10 +347,10 @@ sub get_mw_pages {
>  #        $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
>  sub run_git {
>         my $args = shift;
> -       my $encoding = (shift || "encoding(UTF-8)");
> -       open(my $git, "-|:$encoding", "git " . $args)
> -           or die "Unable to open: $!\n";
> -       my $res = do {
> +       my $encoding = (shift || 'encoding(UTF-8)');
> +       open(my $git, "-|:${encoding}", "git ${args}")
> +           or die "Unable to fork: $!\n";
> +       my $res = do {

The whitespace-only change to line "my $res = do {" is effectively
noise. The reviewer has to stop and puzzle out what changed on the
line before continuing with review of the remaining _real_ changes. It
is a good idea to avoid noise changes if possible.

In this particular case, it's easy to avoid the noise since the
trailing space on that line could/should have been removed in patch
18/28 when the statement was split over multiple lines.

>                 local $/ = undef;
>                 <$git>
>         };
> @@ -475,26 +475,26 @@ sub download_mw_mediafile {
>                 return $response->decoded_content;
>         } else {
>                 print STDERR "Error downloading mediafile from :\n";
> -               print STDERR "URL: $download_url\n";
> -               print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
> +               print STDERR "URL: ${download_url}\n";
> +               print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";

To meet the goals of this patch, would you want to do this instead?

    "Server response: @{[$response->code]} @{[$response->message]}\n";

Whether this is easier or more difficult to read is a matter of
opinion. (Again, this is a genuine question rather than a show of
preference on my part.)

>                 exit 1;
>         }
>  }
> @@ -691,8 +691,7 @@ sub fetch_mw_revisions {
>         my $n = 1;
>         foreach my $page (@pages) {
>                 my $id = $page->{pageid};
> -
> -               print STDERR "page $n/", scalar(@pages), ": ". $page->{title} ."\n";
> +               print STDERR "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";

Similarly:

  "page ${n}/@{[scalar(@pages)]}: @{[$page->{title}]}\n"

>                 $n++;
>                 my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
>                 @revisions = (@page_revs, @revisions);
> @@ -706,7 +705,7 @@ sub fe_escape_path {
>         }
> -       print STDOUT "N inline :$n\n";
> -       literal_data("mediawiki_revision: " . $commit{mw_revision});
> +       print STDOUT "N inline :${n}\n";
> +       literal_data("mediawiki_revision: $commit{mw_revision}");

As questioned earlier, do you want ${commit{mw_revision}}?

>         print STDOUT "\n\n";
>         return;
>  }
> @@ -911,8 +910,8 @@ sub mw_import_revids {
>                 my $page_title = $result_page->{title};
>
>                 if (!exists($pages->{$page_title})) {
> -                       print STDERR "$n/", scalar(@$revision_ids),
> -                               ": Skipping revision #$rev->{revid} of $page_title\n";
> +                       print STDERR "${n}/", scalar(@$revision_ids),
> +                               ": Skipping revision #$rev->{revid} of ${page_title}\n";

Same question as above regarding formatting via "@{[...]}".

>                         next;
>                 }
>
> @@ -937,14 +936,14 @@ sub mw_import_revids {
>                 # If this is a revision of the media page for new version
>                 # of a file do one common commit for both file and media page.
>                 # Else do commit only for that page.
> -               print STDERR "$n/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
> +               print STDERR "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";

Ditto.

>                 import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
>         }

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

* Re: [PATCH v3 00/28] Follow perlcritic's recommandations
  2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
                   ` (27 preceding siblings ...)
  2013-06-09 22:22 ` [PATCH v3 28/28] git-remote-mediawiki: Clearly rewrite double dereference Célestin Matte
@ 2013-06-10  1:09 ` Eric Sunshine
  2013-06-10  8:46   ` Matthieu Moy
  28 siblings, 1 reply; 48+ messages in thread
From: Eric Sunshine @ 2013-06-10  1:09 UTC (permalink / raw)
  To: Célestin Matte; +Cc: Git List, benoit.person, Matthieu Moy

On Sun, Jun 9, 2013 at 6:22 PM, Célestin Matte
<celestin.matte@ensimag.fr> wrote:
> Changes with v2:
> - Remove patch [02/22] about using the Readonly module
> - Split commit [07/22] into 5 different ones

This was easier to review after being split. Thanks.

> - Split commit [14/22] into 2 different ones
> - Patch [17/22] was *not* split: tell me if it is necessary

[now patch 22/28]

You, Matthieu, and Junio should decide, but I again found it
time-consuming and onerous to review with all the changes mashed
together.

> - Remove wrong change in patch [22/22]
>
> Patch about fixing a bug in a regexp (with has been renames "Make a regexp
> clearer"), which had been sent as a separate patch, is reintegrated into this
> series of patches.

Overall, this series was more pleasant and easy to read than previous
versions. With the exception of minor comments, questions, and the
whitespace noise in 22/28, I did not spot any issues worth mentioning
in the remainder of the series.

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

* Re: [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split
  2013-06-09 22:22 ` [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
@ 2013-06-10  8:29   ` Matthieu Moy
  0 siblings, 0 replies; 48+ messages in thread
From: Matthieu Moy @ 2013-06-10  8:29 UTC (permalink / raw)
  To: Célestin Matte; +Cc: git, benoit.person

Célestin Matte <celestin.matte@ensimag.fr> writes:

> A "split ' '" is turned into a "split / /", which changes its behaviour: the
> old method matched a run of whtespaces (/\s*/)

It case there's a v4: whtespaces -> whitespaces.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
  2013-06-10  0:50   ` Eric Sunshine
@ 2013-06-10  8:37   ` Matthieu Moy
  2013-06-10 11:00     ` Célestin Matte
  2013-06-10 16:41     ` Junio C Hamano
  1 sibling, 2 replies; 48+ messages in thread
From: Matthieu Moy @ 2013-06-10  8:37 UTC (permalink / raw)
  To: Célestin Matte; +Cc: git, benoit.person

Célestin Matte <celestin.matte@ensimag.fr> writes:

> @@ -1285,8 +1285,7 @@ sub get_mw_namespace_id {
>  		# Look at configuration file, if the record for that namespace is
>  		# already cached. Namespaces are stored in form:
>  		# "Name_of_namespace:Id_namespace", ex.: "File:6".
> -		my @temp = split(/\n/, run_git("config --get-all remote."
> -						. $remotename .".namespaceCache"));
> +		my @temp = split(/\n/, run_git("config --get-all remote.${remotename}.namespaceCache"));

I tend to prefer the former, as it avoids long lines (> 80 columns)

> @@ -1339,8 +1338,7 @@ sub get_mw_namespace_id {
>  
>  	# Store explicitely requested namespaces on disk
>  	if (!exists $cached_mw_namespace_id{$name}) {
> -		run_git("config --add remote.". $remotename
> -			.".namespaceCache \"". $name .":". $store_id ."\"");
> +		run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));

Same.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v3 00/28] Follow perlcritic's recommandations
  2013-06-10  1:09 ` [PATCH v3 00/28] Follow perlcritic's recommandations Eric Sunshine
@ 2013-06-10  8:46   ` Matthieu Moy
  2013-06-11 12:54     ` Célestin Matte
  0 siblings, 1 reply; 48+ messages in thread
From: Matthieu Moy @ 2013-06-10  8:46 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Célestin Matte, Git List, benoit.person

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Sun, Jun 9, 2013 at 6:22 PM, Célestin Matte
> <celestin.matte@ensimag.fr> wrote:
>> Changes with v2:
>> - Remove patch [02/22] about using the Readonly module
>> - Split commit [07/22] into 5 different ones
>
> This was easier to review after being split. Thanks.
>
>> - Split commit [14/22] into 2 different ones
>> - Patch [17/22] was *not* split: tell me if it is necessary
>
> [now patch 22/28]
>
> You, Matthieu, and Junio should decide, but I again found it
> time-consuming and onerous to review with all the changes mashed
> together.

I agree that it would have been better to split the patches in v1, but
now that we've already spent time reviewing it, it seems unecessary to
spend more time splitting and re-reviewing.

I went through the series once more, all my remarks are minor. I'm OK
with the series as it is (i.e. perhaps it's time to say "stop the
bikeshedding and start coding real stuff" ;-) ). As a reminder: Celestin
is in a school project that ends in a week. The goal is both to be
productive and to learn stuff.

In any case, thanks a lot for your review, Eric.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10  0:50   ` Eric Sunshine
@ 2013-06-10 10:48     ` Célestin Matte
  0 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-10 10:48 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, benoit.person, Matthieu Moy

Le 10/06/2013 02:50, Eric Sunshine a écrit :
> Given this patch's intention to use ${} within strings, should this be
> ${credential{username}}?
> 
> (I don't have a preference, but it's a genuine question since it's not
> clear if this was an oversight or intentional.)

The answer is simple: I didn't know the exact syntax, so I didn't bother
doing it.


> The whitespace-only change to line "my $res = do {" is effectively
> noise. The reviewer has to stop and puzzle out what changed on the
> line before continuing with review of the remaining _real_ changes. It
> is a good idea to avoid noise changes if possible.
> 
> In this particular case, it's easy to avoid the noise since the
> trailing space on that line could/should have been removed in patch
> 18/28 when the statement was split over multiple lines.

Actually, I noticed this but didn't find what the difference between the
two lines was. I assumed git was making some kind of mistake - but eh,
it seems git is never wrong :)

>>                 local $/ = undef;
>>                 <$git>
>>         };
>> @@ -475,26 +475,26 @@ sub download_mw_mediafile {
>>                 return $response->decoded_content;
>>         } else {
>>                 print STDERR "Error downloading mediafile from :\n";
>> -               print STDERR "URL: $download_url\n";
>> -               print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
>> +               print STDERR "URL: ${download_url}\n";
>> +               print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";
> 
> To meet the goals of this patch, would you want to do this instead?
> 
>     "Server response: @{[$response->code]} @{[$response->message]}\n";
> 
> Whether this is easier or more difficult to read is a matter of
> opinion. (Again, this is a genuine question rather than a show of
> preference on my part.)

Same as above, I tried to change it but didn't know the exact syntax, so
I gave up.


-- 
Célestin Matte

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10  8:37   ` Matthieu Moy
@ 2013-06-10 11:00     ` Célestin Matte
  2013-06-10 16:41     ` Junio C Hamano
  1 sibling, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-10 11:00 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, benoit.person

Le 10/06/2013 10:37, Matthieu Moy a écrit :
> Célestin Matte <celestin.matte@ensimag.fr> writes:
> 
>> @@ -1285,8 +1285,7 @@ sub get_mw_namespace_id {
>>  		# Look at configuration file, if the record for that namespace is
>>  		# already cached. Namespaces are stored in form:
>>  		# "Name_of_namespace:Id_namespace", ex.: "File:6".
>> -		my @temp = split(/\n/, run_git("config --get-all remote."
>> -						. $remotename .".namespaceCache"));
>> +		my @temp = split(/\n/, run_git("config --get-all remote.${remotename}.namespaceCache"));
> 
> I tend to prefer the former, as it avoids long lines (> 80 columns)

The 80-columns rule is already broken in *many* places in this file.
I know this is not a valid reason to do it more often, but in my opinion
the second version is easier to read (it's easy to miss the dots in the
first version), so we would gain from the change.


-- 
Célestin Matte

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10  8:37   ` Matthieu Moy
  2013-06-10 11:00     ` Célestin Matte
@ 2013-06-10 16:41     ` Junio C Hamano
  2013-06-10 17:18       ` Benoît Person
  1 sibling, 1 reply; 48+ messages in thread
From: Junio C Hamano @ 2013-06-10 16:41 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Célestin Matte, git, benoit.person

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Célestin Matte <celestin.matte@ensimag.fr> writes:
>
>> @@ -1285,8 +1285,7 @@ sub get_mw_namespace_id {
>>  		# Look at configuration file, if the record for that namespace is
>>  		# already cached. Namespaces are stored in form:
>>  		# "Name_of_namespace:Id_namespace", ex.: "File:6".
>> -		my @temp = split(/\n/, run_git("config --get-all remote."
>> -						. $remotename .".namespaceCache"));
>> +		my @temp = split(/\n/, run_git("config --get-all remote.${remotename}.namespaceCache"));
>
> I tend to prefer the former, as it avoids long lines (> 80 columns)

But you split the name of a single variable across lines by doing so.

You could split lines to make it a bit more readable.

		my @temp = split(/\n/,
			run_git("config --get-all remote.${remotename}.namespaceCache"));

It still overflows the 80-column limit, but the "namespaceCache" is
the only thing that overflows; not much harm is done.

This is totally outside of the topic of "coding-style" series, but I
would be more concerned about the use of ${remotename}, though.  Has
it (and in general the parameters to all calls to run_git()) been
sanitized for shell metacharacters?  If we had a variant of run_git
that took an array of command line arguments given to git, you could
do this

		my @temp = split(/\n/,
			run_git([qw(config --get-all),
                        	"remote.${remotename}.namespaceCache")]);

which would be safer and easier to read.

>> @@ -1339,8 +1338,7 @@ sub get_mw_namespace_id {
>>  
>>  	# Store explicitely requested namespaces on disk
>>  	if (!exists $cached_mw_namespace_id{$name}) {
>> -		run_git("config --add remote.". $remotename
>> -			.".namespaceCache \"". $name .":". $store_id ."\"");
>> +		run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));
>
> Same.

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10 16:41     ` Junio C Hamano
@ 2013-06-10 17:18       ` Benoît Person
  2013-06-10 17:30         ` Matthieu Moy
  0 siblings, 1 reply; 48+ messages in thread
From: Benoît Person @ 2013-06-10 17:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matthieu Moy, Célestin Matte, git

Well, I think next step would be to replace all those calls with
Git.pm `command`, `command_oneline` and `config``which take an array
of arguments after the "command". In the preview tool we use those but
I don't know if we will find the time to clean that up too in
git-remote-mediawiki :) .

Don't know though if it's better to mix that with this serie which is
mainly based on what perlcritic returns.

On 10 June 2013 18:41, Junio C Hamano <gitster@pobox.com> wrote:
> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
>> Célestin Matte <celestin.matte@ensimag.fr> writes:
>>
>>> @@ -1285,8 +1285,7 @@ sub get_mw_namespace_id {
>>>              # Look at configuration file, if the record for that namespace is
>>>              # already cached. Namespaces are stored in form:
>>>              # "Name_of_namespace:Id_namespace", ex.: "File:6".
>>> -            my @temp = split(/\n/, run_git("config --get-all remote."
>>> -                                            . $remotename .".namespaceCache"));
>>> +            my @temp = split(/\n/, run_git("config --get-all remote.${remotename}.namespaceCache"));
>>
>> I tend to prefer the former, as it avoids long lines (> 80 columns)
>
> But you split the name of a single variable across lines by doing so.
>
> You could split lines to make it a bit more readable.
>
>                 my @temp = split(/\n/,
>                         run_git("config --get-all remote.${remotename}.namespaceCache"));
>
> It still overflows the 80-column limit, but the "namespaceCache" is
> the only thing that overflows; not much harm is done.
>
> This is totally outside of the topic of "coding-style" series, but I
> would be more concerned about the use of ${remotename}, though.  Has
> it (and in general the parameters to all calls to run_git()) been
> sanitized for shell metacharacters?  If we had a variant of run_git
> that took an array of command line arguments given to git, you could
> do this
>
>                 my @temp = split(/\n/,
>                         run_git([qw(config --get-all),
>                                 "remote.${remotename}.namespaceCache")]);
>
> which would be safer and easier to read.
>
>>> @@ -1339,8 +1338,7 @@ sub get_mw_namespace_id {
>>>
>>>      # Store explicitely requested namespaces on disk
>>>      if (!exists $cached_mw_namespace_id{$name}) {
>>> -            run_git("config --add remote.". $remotename
>>> -                    .".namespaceCache \"". $name .":". $store_id ."\"");
>>> +            run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));
>>
>> Same.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10 17:18       ` Benoît Person
@ 2013-06-10 17:30         ` Matthieu Moy
  2013-06-10 19:01           ` Junio C Hamano
  0 siblings, 1 reply; 48+ messages in thread
From: Matthieu Moy @ 2013-06-10 17:30 UTC (permalink / raw)
  To: Benoît Person; +Cc: Junio C Hamano, Célestin Matte, git

Please, don't top-post. Quote the part of the message you're replying
to, and reply below.

Benoît Person <benoit.person@ensimag.fr> writes:

> Well, I think next step would be to replace all those calls with
> Git.pm `command`, `command_oneline` and `config``which take an array
> of arguments after the "command". In the preview tool we use those but
> I don't know if we will find the time to clean that up too in
> git-remote-mediawiki :) .

Agreed. run_git was written to avoid having to depend on Git.pm, but now
that we do, we should do it the Git.pm way (although this is not a
high priority for now).

> Don't know though if it's better to mix that with this serie which is
> mainly based on what perlcritic returns.

If you go this way, I'd rather have it on top (i.e. a separate patch
series).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
  2013-06-10 17:30         ` Matthieu Moy
@ 2013-06-10 19:01           ` Junio C Hamano
  0 siblings, 0 replies; 48+ messages in thread
From: Junio C Hamano @ 2013-06-10 19:01 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Benoît Person, Célestin Matte, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Please, don't top-post. Quote the part of the message you're replying
> to, and reply below.
>
> Benoît Person <benoit.person@ensimag.fr> writes:
>
>> Well, I think next step would be to replace all those calls with
>> Git.pm `command`, `command_oneline` and `config``which take an array
>> of arguments after the "command". In the preview tool we use those but
>> I don't know if we will find the time to clean that up too in
>> git-remote-mediawiki :) .
>
> Agreed. run_git was written to avoid having to depend on Git.pm, but now
> that we do, we should do it the Git.pm way (although this is not a
> high priority for now).
>
>> Don't know though if it's better to mix that with this serie which is
>> mainly based on what perlcritic returns.
>
> If you go this way, I'd rather have it on top (i.e. a separate patch
> series).

Or not worry too much about it in the 3-week long school project.
Finish one that you started and then build on top.

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

* Re: [PATCH v3 00/28] Follow perlcritic's recommandations
  2013-06-10  8:46   ` Matthieu Moy
@ 2013-06-11 12:54     ` Célestin Matte
  0 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-11 12:54 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Eric Sunshine, Célestin Matte, Git List, benoit.person

So, do I send a last version of the patch? What is left is quick fix:
- removing whitespace in [18/28]
- typo in [09/28]
- better line split in [22/28]
I already fixed first two problems, so it would be done rapidly.

-- 
Célestin Matte

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

* Re: [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-09 22:22 ` [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
@ 2013-06-11 15:04   ` Junio C Hamano
  2013-06-11 16:35     ` Matthieu Moy
  0 siblings, 1 reply; 48+ messages in thread
From: Junio C Hamano @ 2013-06-11 15:04 UTC (permalink / raw)
  To: Célestin Matte; +Cc: git, benoit.person, matthieu.moy

Célestin Matte <celestin.matte@ensimag.fr> writes:

> Subroutines' parameters should be affected to variable before doing anything
> else
> Besides, existing instruction affected a variable inside a "if", which break
> Git's coding style

I think s/affect/assign/g is what you meant.

By the way, I often see two styles of the "let's take arguments into
parameters before doing anything else" at the beginning of subs:

        my ($namespace) = @_;
	my $namespace = shift;

My impression has been that both are equally common, but the latter
is done more often when picking out small and fixed number of
mandatory parameters upfront (and later, optional parameters are
used by directly reading what remains in @_).  Does Perlcritique say
anything about this issue?

> Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
> ---
>  contrib/mw-to-git/git-remote-mediawiki.perl |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index 431e063..2db6467 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -1333,7 +1333,8 @@ sub get_mw_namespace_id {
>  }
>  
>  sub get_mw_namespace_id_for_page {
> -	if (my ($namespace) = $_[0] =~ /^([^:]*):/) {
> +	my $namespace = shift;
> +	if ($namespace =~ /^([^:]*):/) {
>  		return get_mw_namespace_id($namespace);
>  	} else {
>  		return;

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

* Re: [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine
  2013-06-09 22:22 ` [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
@ 2013-06-11 15:42   ` Junio C Hamano
  2013-06-11 22:24     ` Célestin Matte
  0 siblings, 1 reply; 48+ messages in thread
From: Junio C Hamano @ 2013-06-11 15:42 UTC (permalink / raw)
  To: Célestin Matte; +Cc: git, benoit.person, matthieu.moy

Célestin Matte <celestin.matte@ensimag.fr> writes:

> Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
> ---
>  contrib/mw-to-git/git-remote-mediawiki.perl |   50 +++++++++++++++++----------
>  1 file changed, 31 insertions(+), 19 deletions(-)
>
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index c404e7b..a66cef4 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -126,28 +126,13 @@ $wiki_name =~ s{[^/]*://}{};
>  $wiki_name =~ s/^.*@//;
>  
>  # Commands parser
> -my @cmd;
> +my @cmds;

I am guessing that the new sub, parse_command, uses a local @cmd and
this is an attempt to avoid using the same name, but this renaming
of the variable is not explained.

I also wonder if you need this global @cmd/@cmds.  Instead of
passing cmdref, wouldn't it be simpler to have the helper split the
line, i.e. something like...

	sub parse_command {
		my ($line) = @_;
                my @cmd = split(/ /, $line);
		unless (defined @cmd) {
	                return 0;
		}
                ... check capabilities, list, etc....
		return 1;
	}

        while (<STDIN>) {
        	chomp;
                if (!parse_command($_)) {
			unknown command, aborting
                        last;
		}
	}

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

* Re: [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-11 15:04   ` Junio C Hamano
@ 2013-06-11 16:35     ` Matthieu Moy
  2013-06-11 18:09       ` Junio C Hamano
  0 siblings, 1 reply; 48+ messages in thread
From: Matthieu Moy @ 2013-06-11 16:35 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Célestin Matte, git, benoit.person

Junio C Hamano <gitster@pobox.com> writes:

> Célestin Matte <celestin.matte@ensimag.fr> writes:
>
>> Subroutines' parameters should be affected to variable before doing anything
>> else
>> Besides, existing instruction affected a variable inside a "if", which break
>> Git's coding style
>
> I think s/affect/assign/g is what you meant.

Yes, common false friends for French people ;-).

>       my ($namespace) = @_;
> 	my $namespace = shift;
>
> My impression has been that both are equally common,

The second is the most common in git-remote-mediawiki (but I don't have
any preference nor know what is recommended elsewhere).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-11 16:35     ` Matthieu Moy
@ 2013-06-11 18:09       ` Junio C Hamano
  2013-06-11 20:13         ` Célestin Matte
  0 siblings, 1 reply; 48+ messages in thread
From: Junio C Hamano @ 2013-06-11 18:09 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Célestin Matte, git, benoit.person

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

>>       my ($namespace) = @_;
>> 	my $namespace = shift;
>>
>> My impression has been that both are equally common,
>
> The second is the most common in git-remote-mediawiki (but I don't have
> any preference nor know what is recommended elsewhere).

I wasn't implying I prefer the former.  I was just being curious,
and if the latter is more prevalent in the code _and_ Perlcritique
does not have any issue with it, it is perfectly fine.

Thanks.

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

* Re: [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-11 18:09       ` Junio C Hamano
@ 2013-06-11 20:13         ` Célestin Matte
  2013-06-11 21:55           ` Junio C Hamano
  0 siblings, 1 reply; 48+ messages in thread
From: Célestin Matte @ 2013-06-11 20:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matthieu Moy, Célestin Matte, git, benoit.person

Le 11/06/2013 20:09, Junio C Hamano a écrit :
> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> 
>>>       my ($namespace) = @_;
>>> 	my $namespace = shift;
>>>
>>> My impression has been that both are equally common,
>>
>> The second is the most common in git-remote-mediawiki (but I don't have
>> any preference nor know what is recommended elsewhere).
> 
> I wasn't implying I prefer the former.  I was just being curious,
> and if the latter is more prevalent in the code _and_ Perlcritique
> does not have any issue with it, it is perfectly fine.

Perlcritic doesn't have an issue with any of both cases.
I think the second method is clearer when there is only one argument,
because it makes it clear that there is only one.

-- 
Célestin Matte

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

* Re: [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions
  2013-06-11 20:13         ` Célestin Matte
@ 2013-06-11 21:55           ` Junio C Hamano
  0 siblings, 0 replies; 48+ messages in thread
From: Junio C Hamano @ 2013-06-11 21:55 UTC (permalink / raw)
  To: Célestin Matte; +Cc: Matthieu Moy, git, benoit.person

Célestin Matte <celestin.matte@ensimag.fr> writes:

> Le 11/06/2013 20:09, Junio C Hamano a écrit :
>> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>> 
>>>>       my ($namespace) = @_;
>>>> 	my $namespace = shift;
>>>>
>>>> My impression has been that both are equally common,
>>>
>>> The second is the most common in git-remote-mediawiki (but I don't have
>>> any preference nor know what is recommended elsewhere).
>> 
>> I wasn't implying I prefer the former.  I was just being curious,
>> and if the latter is more prevalent in the code _and_ Perlcritique
>> does not have any issue with it, it is perfectly fine.
>
> Perlcritic doesn't have an issue with any of both cases.

OK.  As this topic is about matching the opinion of Perlcritique, I
think it is fine either way (which was the primary thing that I
wanted to find out).

> I think the second method is clearer when there is only one argument,
> because it makes it clear that there is only one.

Hmm, from the maintenance point of view, the second one invites the
next person to extend this function like this:

	my $namespace = shift;
+       my $newargument = shift;
+	my $anotherargument = shift;

If your original were in the first style, instead you would likely to
get this:

-	my ($namespace) = @_;
+	my ($namespace, $newargument, $anotherargument) = @_;

When there is only one argument, it is clear that there is only one
argument in either style.  It is not a strong factor to pick one
style over the other.  Once you start taking more than one argument,
however, I think "it makes it clear what arguments the function
takes" would actually favor the style to split @_ into a list of
local variables.

But as I said earlier, this patch is about following Perlcritique's
advice, and because it does not have opinion on these styles, it is
outside the scope of this patch.

Thanks for checking.

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

* Re: [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine
  2013-06-11 15:42   ` Junio C Hamano
@ 2013-06-11 22:24     ` Célestin Matte
  0 siblings, 0 replies; 48+ messages in thread
From: Célestin Matte @ 2013-06-11 22:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, benoit.person, matthieu.moy

Oops, forgot to take this into account before sending v4 of my series of
patch. I just noticed that, sorry...

Le 11/06/2013 17:42, Junio C Hamano a écrit :
> I am guessing that the new sub, parse_command, uses a local @cmd and
> this is an attempt to avoid using the same name, but this renaming
> of the variable is not explained.

This is indeed what I intended to do.

> I also wonder if you need this global @cmd/@cmds.  Instead of
> passing cmdref, wouldn't it be simpler to have the helper split the
> line, i.e. something like...
> 
> 	sub parse_command {
> 		my ($line) = @_;
>                 my @cmd = split(/ /, $line);
> 		unless (defined @cmd) {
> 	                return 0;
> 		}
>                 ... check capabilities, list, etc....
> 		return 1;
> 	}
> 
>         while (<STDIN>) {
>         	chomp;
>                 if (!parse_command($_)) {
> 			unknown command, aborting
>                         last;
> 		}
> 	}
> 
> 


-- 
Célestin Matte

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

end of thread, other threads:[~2013-06-11 22:24 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
2013-06-09 22:22 ` [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer Célestin Matte
2013-06-09 22:22 ` [PATCH v3 02/28] git-remote-mediawiki: Move "use warnings;" before any instruction Célestin Matte
2013-06-09 22:22 ` [PATCH v3 03/28] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8) Célestin Matte
2013-06-09 22:22 ` [PATCH v3 04/28] git-remote-mediawiki: Always end a subroutine with a return Célestin Matte
2013-06-09 22:22 ` [PATCH v3 05/28] git-remote-mediawiki: Move a variable declaration at the top of the code Célestin Matte
2013-06-09 22:22 ` [PATCH v3 06/28] git-remote-mediawiki: Change syntax of map calls Célestin Matte
2013-06-09 22:22 ` [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
2013-06-11 15:04   ` Junio C Hamano
2013-06-11 16:35     ` Matthieu Moy
2013-06-11 18:09       ` Junio C Hamano
2013-06-11 20:13         ` Célestin Matte
2013-06-11 21:55           ` Junio C Hamano
2013-06-09 22:22 ` [PATCH v3 08/28] git-remote-mediawiki: Remove useless regexp modifier (m) Célestin Matte
2013-06-09 22:22 ` [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
2013-06-10  8:29   ` Matthieu Moy
2013-06-09 22:22 ` [PATCH v3 10/28] git-remote-mediawiki: Change separator of some regexps Célestin Matte
2013-06-09 22:22 ` [PATCH v3 11/28] git-remote-mediawiki: Change style in a regexp Célestin Matte
2013-06-09 22:22 ` [PATCH v3 12/28] " Célestin Matte
2013-06-09 22:22 ` [PATCH v3 13/28] git-remote-mediawiki: Add newline in the end of die() error messages Célestin Matte
2013-06-09 22:22 ` [PATCH v3 14/28] git-remote-mediawiki: Change the name of a variable Célestin Matte
2013-06-09 22:22 ` [PATCH v3 15/28] git-remote-mediawiki: Turn double-negated expressions into simple expressions Célestin Matte
2013-06-09 22:22 ` [PATCH v3 16/28] git-remote-mediawiki: Remove unused variable $entry Célestin Matte
2013-06-09 22:22 ` [PATCH v3 17/28] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword Célestin Matte
2013-06-09 22:22 ` [PATCH v3 18/28] git-remote-mediawiki: Assign a variable as undef and make proper indentation Célestin Matte
2013-06-09 22:22 ` [PATCH v3 19/28] git-remote-mediawiki: Check return value of open Célestin Matte
2013-06-09 22:22 ` [PATCH v3 20/28] git-remote-mediawiki: remove import of unused open2 Célestin Matte
2013-06-09 22:22 ` [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
2013-06-11 15:42   ` Junio C Hamano
2013-06-11 22:24     ` Célestin Matte
2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
2013-06-10  0:50   ` Eric Sunshine
2013-06-10 10:48     ` Célestin Matte
2013-06-10  8:37   ` Matthieu Moy
2013-06-10 11:00     ` Célestin Matte
2013-06-10 16:41     ` Junio C Hamano
2013-06-10 17:18       ` Benoît Person
2013-06-10 17:30         ` Matthieu Moy
2013-06-10 19:01           ` Junio C Hamano
2013-06-09 22:22 ` [PATCH v3 23/28] git-remote-mediawiki: Brace file handles for print for more clarity Célestin Matte
2013-06-09 22:22 ` [PATCH v3 24/28] git-remote-mediawiki: Replace "unless" statements with negated "if" statements Célestin Matte
2013-06-09 22:22 ` [PATCH v3 25/28] git-remote-mediawiki: Don't use quotes for empty strings Célestin Matte
2013-06-09 22:22 ` [PATCH v3 26/28] git-remote-mediawiki: Put non-trivial numeric values in constants Célestin Matte
2013-06-09 22:22 ` [PATCH v3 27/28] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki") Célestin Matte
2013-06-09 22:22 ` [PATCH v3 28/28] git-remote-mediawiki: Clearly rewrite double dereference Célestin Matte
2013-06-10  1:09 ` [PATCH v3 00/28] Follow perlcritic's recommandations Eric Sunshine
2013-06-10  8:46   ` Matthieu Moy
2013-06-11 12:54     ` Célestin Matte

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 NNTP newsgroup(s).