[PATCH 11/18] Modify strings for a better coding-style

2013-06-06 Thread 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.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |  250 +--
 1 file changed, 124 insertions(+), 126 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 1271527..0e2152d 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -18,14 +18,14 @@ 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;
 use Readonly;
 
 # Mediawiki filenames can contain forward slashes. This variable decides by 
which pattern they should be replaced
-Readonly my $SLASH_REPLACEMENT = %2F;
+Readonly my $SLASH_REPLACEMENT = '%2F';
 
 # It's not always possible to delete pages (may require some
 # privileges). Deleted pages are replaced with this content.
@@ -36,7 +36,7 @@ Readonly my $DELETED_CONTENT = [[Category:Deleted]]\n;
 Readonly my $EMPTY_CONTENT = !-- empty page --\n;
 
 # used to reflect file creation or deletion in diff.
-Readonly my $NULL_SHA1 = ;
+Readonly my $NULL_SHA1 = '';
 
 # Used on Git's side to reflect empty edit messages on the wiki
 Readonly my $EMPTY_MESSAGE = '*Empty MediaWiki Message*';
@@ -50,35 +50,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
@@ -86,13 +86,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 

Re: [PATCH 11/18] Modify strings for a better coding-style

2013-06-06 Thread Eric Sunshine
On Thu, Jun 6, 2013 at 3:34 PM, Célestin Matte
celestin.ma...@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

 Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
 Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
 ---
  contrib/mw-to-git/git-remote-mediawiki.perl |  250 
 +--
  1 file changed, 124 insertions(+), 126 deletions(-)

 diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
 b/contrib/mw-to-git/git-remote-mediawiki.perl
 index 1271527..0e2152d 100755
 --- a/contrib/mw-to-git/git-remote-mediawiki.perl
 +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
 @@ -344,10 +344,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)');
 +   my $res = do {
 +   open(my $git, -|:$encoding, git ${args})
 +   or die Unable to fork: $!\n;
 local $/ = undef;
 $git
 };

A change sneaked in here not mentioned by the commit message and not
related to the other changes. open() is now inside the do{} block.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html