git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 16/22] git-remote-mediawiki: Modify strings for a better coding-style

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 8, 2013, 00:39 UTC
Message-ID
<CAPig+cT6Qw1w4x95oT7PctMz_HnpU0Vwv5Bh=n-uqZQWJjFnBw@mail.gmail.com>
In-Reply-To
<1370641344-4253-17-git-send-email-celestin.matte@ensimag.fr>

On Fri, Jun 7, 2013 at 5:42 PM, Célestin Matte <celestin.matte@ensimag.fr> wrote:

Show 6 quoted lines
> - 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
Distinct changes could (IMHO) be split into separate patches for easier review.
Show 6 quoted lines
> Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
>
> Conflicts:
>
>         contrib/mw-to-git/git-remote-mediawiki.perl

Conflict information is not interesting to reviewers or even in final commit messages since (hopefully) you will have resolved conflicts before committing. They can be stripped.

More below.
Show 19 quoted lines
> ---
>  contrib/mw-to-git/git-remote-mediawiki.perl |  244 +++++++++++++--------------
>  1 file changed, 121 insertions(+), 123 deletions(-)
>
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index f37488b..2d4ea1d 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -199,10 +199,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 ' .

This change from patch 17/22 (adding braces around file handles) sneaked in early with this patch (16/22).

Show 13 quoted lines
>                                 $mediawiki->{error}->{code} . ': ' .
>                                 $mediawiki->{error}->{details} . ")\n";
>                         Git::credential \%credential, 'reject';
> @@ -473,27 +473,27 @@ 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 . " " . $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";
Ditto: Sneak in from 17/22.
Show 32 quoted lines
>                 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;
>  }
> @@ -690,8 +690,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";
Again 17/22.
Show 12 quoted lines
>                 $n++;
>                 my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
>                 @revisions = (@page_revs, @revisions);
> @@ -705,7 +704,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 {
Previous: Célestin MatteNext: Célestin Matte
Message 31 of 41 in “git-remote-mediawiki: Follow perlcritic's recommandations”
  1. 00/22 git-remote-mediawiki: Follow perlcritic's recommandationsCélestin Matte, Jun 7, 2013
  2. 01/22 git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8)Célestin Matte, Jun 7, 2013
  3. 02/22 git-remote-mediawiki: Use the Readonly module instead of the constant pragmaCélestin Matte, Jun 7, 2013
  4. Jeff KingJun 8, 2013
  5. Benoît PersonJun 8, 2013
  6. Célestin PerduJun 8, 2013
  7. Jeff KingJun 8, 2013
  8. Matthieu MoyJun 8, 2013
  9. 03/22 git-remote-mediawiki: Always end a subroutine with a returnCélestin Matte, Jun 7, 2013
  10. 04/22 git-remote-mediawiki: Move a variable declaration at the top of the codeCélestin Matte, Jun 7, 2013
  11. 05/22 git-remote-mediawiki: Change syntax of map callsCélestin Matte, Jun 7, 2013
  12. 06/22 git-remote-mediawiki: Rewrite unclear line of instructionsCélestin Matte, Jun 7, 2013
  13. 07/22 git-remote-mediawiki: Change style of some regular expressionsCélestin Matte, Jun 7, 2013
  14. Eric SunshineJun 8, 2013
  15. 08/22 git-remote-mediawiki: Add newline in the end of die() error messagesCélestin Matte, Jun 7, 2013
  16. 09/22 git-remote-mediawiki: Change the name of a variableCélestin Matte, Jun 7, 2013
  17. 10/22 git-remote-mediawiki: Turn double-negated expressions into simple expressionsCélestin Matte, Jun 7, 2013
  18. 11/22 git-remote-mediawiki: Remove unused variable $entryCélestin Matte, Jun 7, 2013
  19. 12/22 git-remote-mediawiki: Rename a variable ($last) which has the name of a keywordCélestin Matte, Jun 7, 2013
  20. 13/22 git-remote-mediawiki: Assign a variable as undef and make proper indentationCélestin Matte, Jun 7, 2013
  21. 14/22 git-remote-mediawiki: Check return value of open + remove import of unused open2Célestin Matte, Jun 7, 2013
  22. Eric SunshineJun 8, 2013
  23. Célestin MatteJun 8, 2013
  24. Matthieu MoyJun 8, 2013
  25. Célestin MatteJun 8, 2013
  26. Matthieu MoyJun 8, 2013
  27. Eric SunshineJun 9, 2013
  28. 15/22 git-remote-mediawiki: Put long code into a subroutineCélestin Matte, Jun 7, 2013
  29. Eric SunshineJun 8, 2013
  30. 16/22 git-remote-mediawiki: Modify strings for a better coding-styleCélestin Matte, Jun 7, 2013
  31. Eric SunshineJun 8, 2013
  32. Célestin MatteJun 8, 2013
  33. Eric SunshineJun 9, 2013
  34. 17/22 git-remote-mediawiki: Brace file handles for print for more clarityCélestin Matte, Jun 7, 2013
  35. Eric SunshineJun 8, 2013
  36. 18/22 git-remote-mediawiki: Replace "unless" statements with negated "if" statementsCélestin Matte, Jun 7, 2013
  37. 19/22 git-remote-mediawiki: Don't use quotes for empty stringsCélestin Matte, Jun 7, 2013
  38. 20/22 git-remote-mediawiki: Put non-trivial numeric values in constants.Célestin Matte, Jun 7, 2013
  39. 21/22 git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki")Célestin Matte, Jun 7, 2013
  40. 22/22 git-remote-mediawiki: Clearly rewrite double dereferenceCélestin Matte, Jun 7, 2013
  41. Eric SunshineJun 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.