git-remote-mediawiki: modify strings for a better coding-style
- 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Célestin Matte committed
Jun 14, 2013 at 15:50 UTC
86e95ef2d4803c0fd2cac1afdd66c702ee2bafc1
1 file changed
+119
-120
contrib/mw-to-git/git-remote-mediawiki.perl
+119
-120
@@ -18,13 +18,13 @@ use DateTime::Format::ISO8601;
18
use warnings;
19
20
# By default, use UTF-8 to communicate with Git and the user
21
-binmode STDERR, ":encoding(UTF-8)";
22
-binmode STDOUT, ":encoding(UTF-8)";
21
+binmode STDERR, ':encoding(UTF-8)';
22
+binmode STDOUT, ':encoding(UTF-8)';
23
24
use URI::Escape;
25
26
# Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced
27
-use constant SLASH_REPLACEMENT => "%2F";
27
+use constant SLASH_REPLACEMENT => '%2F';
28
29
# It's not always possible to delete pages (may require some
30
# privileges). Deleted pages are replaced with this content.
@@ -35,7 +35,7 @@ use constant DELETED_CONTENT => "[[Category:Deleted]]\n";
35
use constant EMPTY_CONTENT => "<!-- empty page -->\n";
36
37
# used to reflect file creation or deletion in diff.
38
-use constant NULL_SHA1 => "0000000000000000000000000000000000000000";
38
+use constant NULL_SHA1 => '0000000000000000000000000000000000000000';
39
40
# Used on Git's side to reflect empty edit messages on the wiki
41
use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
@@ -45,35 +45,35 @@ my $url = $ARGV[1];
45
46
# Accept both space-separated and multiple keys in config file.
47
# Spaces should be written as _ anyway because we'll use chomp.
48
-my @tracked_pages = split(/[ \n]/, run_git("config --get-all remote.". $remotename .".pages"));
48
+my @tracked_pages = split(/[ \n]/, run_git("config --get-all remote.${remotename}.pages"));
49
chomp(@tracked_pages);
50
51
# Just like @tracked_pages, but for MediaWiki categories.
52
-my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.". $remotename .".categories"));
52
+my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
53
chomp(@tracked_categories);
54
55
# Import media files on pull
56
-my $import_media = run_git("config --get --bool remote.". $remotename .".mediaimport");
56
+my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
57
chomp($import_media);
58
-$import_media = ($import_media eq "true");
58
+$import_media = ($import_media eq 'true');
59
60
# Export media files on push
61
-my $export_media = run_git("config --get --bool remote.". $remotename .".mediaexport");
61
+my $export_media = run_git("config --get --bool remote.${remotename}.mediaexport");
62
chomp($export_media);
63
-$export_media = !($export_media eq "false");
63
+$export_media = !($export_media eq 'false');
64
65
-my $wiki_login = run_git("config --get remote.". $remotename .".mwLogin");
65
+my $wiki_login = run_git("config --get remote.${remotename}.mwLogin");
66
# Note: mwPassword is discourraged. Use the credential system instead.
67
-my $wiki_passwd = run_git("config --get remote.". $remotename .".mwPassword");
68
-my $wiki_domain = run_git("config --get remote.". $remotename .".mwDomain");
67
+my $wiki_passwd = run_git("config --get remote.${remotename}.mwPassword");
68
+my $wiki_domain = run_git("config --get remote.${remotename}.mwDomain");
69
chomp($wiki_login);
70
chomp($wiki_passwd);
71
chomp($wiki_domain);
72
73
# Import only last revisions (both for clone and fetch)
74
-my $shallow_import = run_git("config --get --bool remote.". $remotename .".shallow");
74
+my $shallow_import = run_git("config --get --bool remote.${remotename}.shallow");
75
chomp($shallow_import);
76
-$shallow_import = ($shallow_import eq "true");
76
+$shallow_import = ($shallow_import eq 'true');
77
78
# Fetch (clone and pull) by revisions instead of by pages. This behavior
79
# is more efficient when we have a wiki with lots of pages and we fetch
@@ -81,13 +81,13 @@ $shallow_import = ($shallow_import eq "true");
81
# Possible values:
82
# - by_rev: perform one query per new revision on the remote wiki
83
# - by_page: query each tracked page for new revision
84
-my $fetch_strategy = run_git("config --get remote.$remotename.fetchStrategy");
84
+my $fetch_strategy = run_git("config --get remote.${remotename}.fetchStrategy");
85
unless ($fetch_strategy) {
86
- $fetch_strategy = run_git("config --get mediawiki.fetchStrategy");
86
+ $fetch_strategy = run_git('config --get mediawiki.fetchStrategy');
87
}
88
chomp($fetch_strategy);
89
unless ($fetch_strategy) {
90
- $fetch_strategy = "by_page";
90
+ $fetch_strategy = 'by_page';
91
}
92
93
# Remember the timestamp corresponding to a revision id.
@@ -107,12 +107,12 @@ my %basetimestamps;
107
# will get the history with information lost). If the import is
108
# deterministic, this means everybody gets the same sha1 for each
109
# MediaWiki revision.
110
-my $dumb_push = run_git("config --get --bool remote.$remotename.dumbPush");
110
+my $dumb_push = run_git("config --get --bool remote.${remotename}.dumbPush");
111
unless ($dumb_push) {
112
- $dumb_push = run_git("config --get --bool mediawiki.dumbPush");
112
+ $dumb_push = run_git('config --get --bool mediawiki.dumbPush');
113
}
114
chomp($dumb_push);
115
-$dumb_push = ($dumb_push eq "true");
115
+$dumb_push = ($dumb_push eq 'true');
116
117
my $wiki_name = $url;
118
$wiki_name =~ s{[^/]*://}{};
@@ -141,22 +141,22 @@ sub parse_command {
141
if (!defined $cmd[0]) {
142
return 0;
143
}
144
- if ($cmd[0] eq "capabilities") {
144
+ if ($cmd[0] eq 'capabilities') {
145
die("Too many arguments for capabilities\n")
146
if (defined($cmd[1]));
147
mw_capabilities();
148
- } elsif ($cmd[0] eq "list") {
148
+ } elsif ($cmd[0] eq 'list') {
149
die("Too many arguments for list\n") if (defined($cmd[2]));
150
mw_list($cmd[1]);
151
- } elsif ($cmd[0] eq "import") {
151
+ } elsif ($cmd[0] eq 'import') {
152
die("Invalid arguments for import\n")
153
if ($cmd[1] eq "" || defined($cmd[2]));
154
mw_import($cmd[1]);
155
- } elsif ($cmd[0] eq "option") {
155
+ } elsif ($cmd[0] eq 'option') {
156
die("Too many arguments for option\n")
157
if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
158
mw_option($cmd[1],$cmd[2]);
159
- } elsif ($cmd[0] eq "push") {
159
+ } elsif ($cmd[0] eq 'push') {
160
mw_push($cmd[1]);
161
} else {
162
print STDERR "Unknown command. Aborting...\n";
@@ -173,7 +173,7 @@ sub mw_connect_maybe {
173
return;
174
}
175
$mediawiki = MediaWiki::API->new;
176
- $mediawiki->{config}->{api_url} = "$url/api.php";
176
+ $mediawiki->{config}->{api_url} = "${url}/api.php";
177
if ($wiki_login) {
178
my %credential = (
179
'url' => $url,
@@ -186,10 +186,10 @@ sub mw_connect_maybe {
186
lgdomain => $wiki_domain};
187
if ($mediawiki->login($request)) {
188
Git::credential(\%credential, 'approve');
189
- print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
189
+ print STDERR qq(Logged in mediawiki user "$credential{username}".\n);
190
} else {
191
- print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
192
- print STDERR " (error " .
191
+ print STDERR qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);
192
+ print STDERR ' (error ' .
193
$mediawiki->{error}->{code} . ': ' .
194
$mediawiki->{error}->{details} . ")\n";
195
Git::credential(\%credential, 'reject');
@@ -245,7 +245,7 @@ sub get_mw_tracked_categories {
245
# Mediawiki requires the Category
246
# prefix, but let's not force the user
247
# to specify it.
248
- $category = "Category:" . $category;
248
+ $category = "Category:${category}";
249
}
250
my $mw_pages = $mediawiki->list( {
251
action => 'query',
@@ -343,9 +343,9 @@ sub get_mw_pages {
343
# $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
344
sub run_git {
345
my $args = shift;
346
- my $encoding = (shift || "encoding(UTF-8)");
347
- open(my $git, "-|:$encoding", "git " . $args)
348
- or die "Unable to open: $!\n";
346
+ my $encoding = (shift || 'encoding(UTF-8)');
347
+ open(my $git, "-|:${encoding}", "git ${args}")
348
+ or die "Unable to fork: $!\n";
349
my $res = do {
350
local $/ = undef;
351
<$git>
@@ -364,7 +364,7 @@ sub get_all_mediafiles {
364
my $mw_pages = $mediawiki->list({
365
action => 'query',
366
list => 'allpages',
367
- apnamespace => get_mw_namespace_id("File"),
367
+ apnamespace => get_mw_namespace_id('File'),
368
aplimit => 'max'
369
});
370
if (!defined($mw_pages)) {
@@ -401,7 +401,7 @@ sub get_linked_mediafiles {
401
action => 'query',
402
prop => 'links|images',
403
titles => $mw_titles,
404
- plnamespace => get_mw_namespace_id("File"),
404
+ plnamespace => get_mw_namespace_id('File'),
405
pllimit => 'max'
406
};
407
my $result = $mediawiki->api($query);
@@ -439,7 +439,7 @@ sub get_mw_mediafile_for_page_revision {
439
my $query = {
440
action => 'query',
441
prop => 'imageinfo',
442
- titles => "File:" . $filename,
442
+ titles => "File:${filename}",
443
iistart => $timestamp,
444
iiend => $timestamp,
445
iiprop => 'timestamp|archivename|url',
@@ -471,26 +471,26 @@ sub download_mw_mediafile {
471
return $response->decoded_content;
472
} else {
473
print STDERR "Error downloading mediafile from :\n";
474
- print STDERR "URL: $download_url\n";
475
- print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
474
+ print STDERR "URL: ${download_url}\n";
475
+ print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";
476
exit 1;
477
}
478
}
479
480
sub get_last_local_revision {
481
# Get note regarding last mediawiki revision
482
- my $note = run_git("notes --ref=$remotename/mediawiki show refs/mediawiki/$remotename/master 2>/dev/null");
482
+ my $note = run_git("notes --ref=${remotename}/mediawiki show refs/mediawiki/${remotename}/master 2>/dev/null");
483
my @note_info = split(/ /, $note);
484
485
my $lastrevision_number;
486
- if (!(defined($note_info[0]) && $note_info[0] eq "mediawiki_revision:")) {
487
- print STDERR "No previous mediawiki revision found";
486
+ if (!(defined($note_info[0]) && $note_info[0] eq 'mediawiki_revision:')) {
487
+ print STDERR 'No previous mediawiki revision found';
488
$lastrevision_number = 0;
489
} else {
490
# Notes are formatted : mediawiki_revision: #number
491
$lastrevision_number = $note_info[1];
492
chomp($lastrevision_number);
493
- print STDERR "Last local mediawiki revision found is $lastrevision_number";
493
+ print STDERR "Last local mediawiki revision found is ${lastrevision_number}";
494
}
495
return $lastrevision_number;
496
}
@@ -569,7 +569,7 @@ sub mediawiki_smudge {
569
$string = "";
570
}
571
# This \n is important. This is due to mediawiki's way to handle end of files.
572
- return $string."\n";
572
+ return "${string}\n";
573
}
574
575
sub mediawiki_clean_filename {
@@ -591,13 +591,13 @@ sub mediawiki_smudge_filename {
591
$filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;
592
$filename =~ s/ /_/g;
593
# Decode forbidden characters encoded in mediawiki_clean_filename
594
- $filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf("%c", hex($1))/ge;
594
+ $filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf('%c', hex($1))/ge;
595
return $filename;
596
}
597
598
sub literal_data {
599
my ($content) = @_;
600
- print STDOUT "data ", bytes::length($content), "\n", $content;
600
+ print STDOUT 'data ', bytes::length($content), "\n", $content;
601
return;
602
}
603
@@ -606,9 +606,9 @@ sub literal_data_raw {
606
my ($content) = @_;
607
# Avoid confusion between size in bytes and in characters
608
utf8::downgrade($content);
609
- binmode STDOUT, ":raw";
610
- print STDOUT "data ", bytes::length($content), "\n", $content;
611
- binmode STDOUT, ":encoding(UTF-8)";
609
+ binmode STDOUT, ':raw';
610
+ print STDOUT 'data ', bytes::length($content), "\n", $content;
611
+ binmode STDOUT, ':encoding(UTF-8)';
612
return;
613
}
614
@@ -616,7 +616,7 @@ sub mw_capabilities {
616
# Revisions are imported to the private namespace
617
# refs/mediawiki/$remotename/ by the helper and fetched into
618
# refs/remotes/$remotename later by fetch.
619
- print STDOUT "refspec refs/heads/*:refs/mediawiki/$remotename/*\n";
619
+ print STDOUT "refspec refs/heads/*:refs/mediawiki/${remotename}/*\n";
620
print STDOUT "import\n";
621
print STDOUT "list\n";
622
print STDOUT "push\n";
@@ -675,7 +675,7 @@ sub fetch_mw_revisions_for_page {
675
@page_revs = sort {$b->{revid} <=> $a->{revid}} (@page_revs);
676
return $page_revs[0];
677
}
678
- print STDERR " Found ", $revnum, " revision(s).\n";
678
+ print STDERR " Found ${revnum} revision(s).\n";
679
return @page_revs;
680
}
681
@@ -687,8 +687,7 @@ sub fetch_mw_revisions {
687
my $n = 1;
688
foreach my $page (@pages) {
689
my $id = $page->{pageid};
690
-
691
- print STDERR "page $n/", scalar(@pages), ": ". $page->{title} ."\n";
690
+ print STDERR "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";
691
$n++;
692
my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
693
@revisions = (@page_revs, @revisions);
@@ -702,7 +701,7 @@ sub fe_escape_path {
701
$path =~ s/\\/\\\\/g;
702
$path =~ s/"/\\"/g;
703
$path =~ s/\n/\\n/g;
705
- return '"' . $path . '"';
704
+ return qq("${path}");
705
}
706
707
sub import_file_revision {
@@ -722,41 +721,41 @@ sub import_file_revision {
721
my $author = $commit{author};
722
my $date = $commit{date};
723
725
- print STDOUT "commit refs/mediawiki/$remotename/master\n";
726
- print STDOUT "mark :$n\n";
727
- print STDOUT "committer $author <$author\@$wiki_name> ", $date->epoch, " +0000\n";
724
+ print STDOUT "commit refs/mediawiki/${remotename}/master\n";
725
+ print STDOUT "mark :${n}\n";
726
+ print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
727
literal_data($comment);
728
729
# If it's not a clone, we need to know where to start from
730
if (!$full_import && $n == 1) {
732
- print STDOUT "from refs/mediawiki/$remotename/master^0\n";
731
+ print STDOUT "from refs/mediawiki/${remotename}/master^0\n";
732
}
733
if ($content ne DELETED_CONTENT) {
735
- print STDOUT "M 644 inline " .
736
- fe_escape_path($title . ".mw") . "\n";
734
+ print STDOUT 'M 644 inline ' .
735
+ fe_escape_path("${title}.mw") . "\n";
736
literal_data($content);
737
if (%mediafile) {
739
- print STDOUT "M 644 inline "
738
+ print STDOUT 'M 644 inline '
739
. fe_escape_path($mediafile{title}) . "\n";
740
literal_data_raw($mediafile{content});
741
}
742
print STDOUT "\n\n";
743
} else {
745
- print STDOUT "D " . fe_escape_path($title . ".mw") . "\n";
744
+ print STDOUT 'D ' . fe_escape_path("${title}.mw") . "\n";
745
}
746
747
# mediawiki revision number in the git note
748
if ($full_import && $n == 1) {
750
- print STDOUT "reset refs/notes/$remotename/mediawiki\n";
749
+ print STDOUT "reset refs/notes/${remotename}/mediawiki\n";
750
}
752
- print STDOUT "commit refs/notes/$remotename/mediawiki\n";
753
- print STDOUT "committer $author <$author\@$wiki_name> ", $date->epoch, " +0000\n";
754
- literal_data("Note added by git-mediawiki during import");
751
+ print STDOUT "commit refs/notes/${remotename}/mediawiki\n";
752
+ print STDOUT "committer ${author} <${author}\@${wiki_name}> " . $date->epoch . " +0000\n";
753
+ literal_data('Note added by git-mediawiki during import');
754
if (!$full_import && $n == 1) {
756
- print STDOUT "from refs/notes/$remotename/mediawiki^0\n";
755
+ print STDOUT "from refs/notes/${remotename}/mediawiki^0\n";
756
}
758
- print STDOUT "N inline :$n\n";
759
- literal_data("mediawiki_revision: " . $commit{mw_revision});
757
+ print STDOUT "N inline :${n}\n";
758
+ literal_data("mediawiki_revision: $commit{mw_revision}");
759
print STDOUT "\n\n";
760
return;
761
}
@@ -784,7 +783,7 @@ sub get_more_refs {
783
784
sub mw_import {
785
# multiple import commands can follow each other.
787
- my @refs = (shift, get_more_refs("import"));
786
+ my @refs = (shift, get_more_refs('import'));
787
foreach my $ref (@refs) {
788
mw_import_ref($ref);
789
}
@@ -799,7 +798,7 @@ sub mw_import_ref {
798
# Since HEAD is a symbolic ref to master (by convention,
799
# followed by the output of the command "list" that we gave),
800
# we don't need to do anything in this case.
802
- if ($ref eq "HEAD") {
801
+ if ($ref eq 'HEAD') {
802
return;
803
}
804
@@ -815,15 +814,15 @@ sub mw_import_ref {
814
}
815
816
my $n = 0;
818
- if ($fetch_strategy eq "by_rev") {
817
+ if ($fetch_strategy eq 'by_rev') {
818
print STDERR "Fetching & writing export data by revs...\n";
819
$n = mw_import_ref_by_revs($fetch_from);
821
- } elsif ($fetch_strategy eq "by_page") {
820
+ } elsif ($fetch_strategy eq 'by_page') {
821
print STDERR "Fetching & writing export data by pages...\n";
822
$n = mw_import_ref_by_pages($fetch_from);
823
} else {
825
- print STDERR "fatal: invalid fetch strategy \"$fetch_strategy\".\n";
826
- print STDERR "Check your configuration variables remote.$remotename.fetchStrategy and mediawiki.fetchStrategy\n";
824
+ print STDERR qq(fatal: invalid fetch strategy "${fetch_strategy}".\n);
825
+ print STDERR "Check your configuration variables remote.${remotename}.fetchStrategy and mediawiki.fetchStrategy\n";
826
exit 1;
827
}
828
@@ -897,7 +896,7 @@ sub mw_import_revids {
896
}
897
898
if (!defined($result->{query}->{pages})) {
900
- die "Invalid revision $pagerevid.\n";
899
+ die "Invalid revision ${pagerevid}.\n";
900
}
901
902
my @result_pages = values(%{$result->{query}->{pages}});
@@ -907,8 +906,8 @@ sub mw_import_revids {
906
my $page_title = $result_page->{title};
907
908
if (!exists($pages->{$page_title})) {
910
- print STDERR "$n/", scalar(@$revision_ids),
911
- ": Skipping revision #$rev->{revid} of $page_title\n";
909
+ print STDERR "${n}/", scalar(@$revision_ids),
910
+ ": Skipping revision #$rev->{revid} of ${page_title}\n";
911
next;
912
}
913
@@ -933,14 +932,14 @@ sub mw_import_revids {
932
my %mediafile;
933
if ($namespace) {
934
my $id = get_mw_namespace_id($namespace);
936
- if ($id && $id == get_mw_namespace_id("File")) {
935
+ if ($id && $id == get_mw_namespace_id('File')) {
936
%mediafile = get_mw_mediafile_for_page_revision($filename, $rev->{timestamp});
937
}
938
}
939
# If this is a revision of the media page for new version
940
# of a file do one common commit for both file and media page.
941
# Else do commit only for that page.
943
- print STDERR "$n/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
942
+ print STDERR "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
943
import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
944
}
945
@@ -948,9 +947,9 @@ sub mw_import_revids {
947
}
948
949
sub error_non_fast_forward {
951
- my $advice = run_git("config --bool advice.pushNonFastForward");
950
+ my $advice = run_git('config --bool advice.pushNonFastForward');
951
chomp($advice);
953
- if ($advice ne "false") {
952
+ if ($advice ne 'false') {
953
# Native git-push would show this after the summary.
954
# We can't ask it to display it cleanly, so print it
955
# ourselves before.
@@ -958,7 +957,7 @@ sub error_non_fast_forward {
957
print STDERR "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
958
print STDERR "'Note about fast-forwards' section of 'git push --help' for details.\n";
959
}
961
- print STDOUT "error $_[0] \"non-fast-forward\"\n";
960
+ print STDOUT qq(error $_[0] "non-fast-forward"\n);
961
return 0;
962
}
963
@@ -969,10 +968,10 @@ sub mw_upload_file {
968
my $file_deleted = shift;
969
my $summary = shift;
970
my $newrevid;
972
- my $path = "File:" . $complete_file_name;
971
+ my $path = "File:${complete_file_name}";
972
my %hashFiles = get_allowed_file_extensions();
973
if (!exists($hashFiles{$extension})) {
975
- print STDERR "$complete_file_name is not a permitted file on this wiki.\n";
974
+ print STDERR "${complete_file_name} is not a permitted file on this wiki.\n";
975
print STDERR "Check the configuration of file uploads in your mediawiki.\n";
976
return $newrevid;
977
}
@@ -992,11 +991,11 @@ sub mw_upload_file {
991
}
992
} else {
993
# Don't let perl try to interpret file content as UTF-8 => use "raw"
995
- my $content = run_git("cat-file blob $new_sha1", "raw");
994
+ my $content = run_git("cat-file blob ${new_sha1}", 'raw');
995
if ($content ne "") {
996
mw_connect_maybe();
997
$mediawiki->{config}->{upload_url} =
999
- "$url/index.php/Special:Upload";
998
+ "${url}/index.php/Special:Upload";
999
$mediawiki->edit({
1000
action => 'upload',
1001
filename => $complete_file_name,
@@ -1011,9 +1010,9 @@ sub mw_upload_file {
1010
. $mediawiki->{error}->{details} . "\n";
1011
my $last_file_page = $mediawiki->get_page({title => $path});
1012
$newrevid = $last_file_page->{revid};
1014
- print STDERR "Pushed file: $new_sha1 - $complete_file_name.\n";
1013
+ print STDERR "Pushed file: ${new_sha1} - ${complete_file_name}.\n";
1014
} else {
1016
- print STDERR "Empty file $complete_file_name not pushed.\n";
1015
+ print STDERR "Empty file ${complete_file_name} not pushed.\n";
1016
}
1017
}
1018
return $newrevid;
@@ -1048,11 +1047,11 @@ sub mw_push_file {
1047
if (!defined($extension)) {
1048
$extension = "";
1049
}
1051
- if ($extension eq "mw") {
1050
+ if ($extension eq 'mw') {
1051
my $ns = get_mw_namespace_id_for_page($complete_file_name);
1053
- if ($ns && $ns == get_mw_namespace_id("File") && (!$export_media)) {
1054
- print STDERR "Ignoring media file related page: $complete_file_name\n";
1055
- return ($oldrevid, "ok");
1052
+ if ($ns && $ns == get_mw_namespace_id('File') && (!$export_media)) {
1053
+ print STDERR "Ignoring media file related page: ${complete_file_name}\n";
1054
+ return ($oldrevid, 'ok');
1055
}
1056
my $file_content;
1057
if ($page_deleted) {
@@ -1062,7 +1061,7 @@ sub mw_push_file {
1061
# with this content instead:
1062
$file_content = DELETED_CONTENT;
1063
} else {
1065
- $file_content = run_git("cat-file blob $new_sha1");
1064
+ $file_content = run_git("cat-file blob ${new_sha1}");
1065
}
1066
1067
mw_connect_maybe();
@@ -1083,7 +1082,7 @@ sub mw_push_file {
1082
$mediawiki->{error}->{code} .
1083
' from mediwiki: ' . $mediawiki->{error}->{details} .
1084
".\n";
1086
- return ($oldrevid, "non-fast-forward");
1085
+ return ($oldrevid, 'non-fast-forward');
1086
} else {
1087
# Other errors. Shouldn't happen => just die()
1088
die 'Fatal: Error ' .
@@ -1092,21 +1091,21 @@ sub mw_push_file {
1091
}
1092
}
1093
$newrevid = $result->{edit}->{newrevid};
1095
- print STDERR "Pushed file: $new_sha1 - $title\n";
1094
+ print STDERR "Pushed file: ${new_sha1} - ${title}\n";
1095
} elsif ($export_media) {
1096
$newrevid = mw_upload_file($complete_file_name, $new_sha1,
1097
$extension, $page_deleted,
1098
$summary);
1099
} else {
1101
- print STDERR "Ignoring media file $title\n";
1100
+ print STDERR "Ignoring media file ${title}\n";
1101
}
1102
$newrevid = ($newrevid or $oldrevid);
1104
- return ($newrevid, "ok");
1103
+ return ($newrevid, 'ok');
1104
}
1105
1106
sub mw_push {
1107
# multiple push statements can follow each other
1109
- my @refsspecs = (shift, get_more_refs("push"));
1108
+ my @refsspecs = (shift, get_more_refs('push'));
1109
my $pushed;
1110
for my $refspec (@refsspecs) {
1111
my ($force, $local, $remote) = $refspec =~ /^(\+)?([^:]*):([^:]*)$/
@@ -1116,12 +1115,12 @@ sub mw_push {
1115
}
1116
if ($local eq "") {
1117
print STDERR "Cannot delete remote branch on a MediaWiki\n";
1119
- print STDOUT "error $remote cannot delete\n";
1118
+ print STDOUT "error ${remote} cannot delete\n";
1119
next;
1120
}
1122
- if ($remote ne "refs/heads/master") {
1121
+ if ($remote ne 'refs/heads/master') {
1122
print STDERR "Only push to the branch 'master' is supported on a MediaWiki\n";
1124
- print STDOUT "error $remote only master allowed\n";
1123
+ print STDOUT "error ${remote} only master allowed\n";
1124
next;
1125
}
1126
if (mw_push_revision($local, $remote)) {
@@ -1152,9 +1151,10 @@ sub mw_push_revision {
1151
my $mw_revision = $last_remote_revid;
1152
1153
# Get sha1 of commit pointed by local HEAD
1155
- my $HEAD_sha1 = run_git("rev-parse $local 2>/dev/null"); chomp($HEAD_sha1);
1154
+ my $HEAD_sha1 = run_git("rev-parse ${local} 2>/dev/null");
1155
+ chomp($HEAD_sha1);
1156
# Get sha1 of commit pointed by remotes/$remotename/master
1157
- my $remoteorigin_sha1 = run_git("rev-parse refs/remotes/$remotename/master 2>/dev/null");
1157
+ my $remoteorigin_sha1 = run_git("rev-parse refs/remotes/${remotename}/master 2>/dev/null");
1158
chomp($remoteorigin_sha1);
1159
1160
if ($last_local_revid > 0 &&
@@ -1174,7 +1174,7 @@ sub mw_push_revision {
1174
my $parsed_sha1 = $remoteorigin_sha1;
1175
# Find a path from last MediaWiki commit to pushed commit
1176
print STDERR "Computing path from local to remote ...\n";
1177
- my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents $local ^$parsed_sha1"));
1177
+ my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents ${local} ^${parsed_sha1}"));
1178
my %local_ancestry;
1179
foreach my $line (@local_ancestry) {
1180
if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
@@ -1182,7 +1182,7 @@ sub mw_push_revision {
1182
$local_ancestry{$parent} = $child;
1183
}
1184
} elsif (!$line =~ /^([a-f0-9]+)/) {
1185
- die "Unexpected output from git rev-list: $line\n";
1185
+ die "Unexpected output from git rev-list: ${line}\n";
1186
}
1187
}
1188
while ($parsed_sha1 ne $HEAD_sha1) {
@@ -1198,7 +1198,7 @@ sub mw_push_revision {
1198
# No remote mediawiki revision. Export the whole
1199
# history (linearized with --first-parent)
1200
print STDERR "Warning: no common ancestor, pushing complete history\n";
1201
- my $history = run_git("rev-list --first-parent --children $local");
1201
+ my $history = run_git("rev-list --first-parent --children ${local}");
1202
my @history = split(/\n/, $history);
1203
@history = @history[1..$#history];
1204
foreach my $line (reverse @history) {
@@ -1210,12 +1210,12 @@ sub mw_push_revision {
1210
foreach my $commit_info_split (@commit_pairs) {
1211
my $sha1_child = @{$commit_info_split}[0];
1212
my $sha1_commit = @{$commit_info_split}[1];
1213
- my $diff_infos = run_git("diff-tree -r --raw -z $sha1_child $sha1_commit");
1213
+ my $diff_infos = run_git("diff-tree -r --raw -z ${sha1_child} ${sha1_commit}");
1214
# TODO: we could detect rename, and encode them with a #redirect on the wiki.
1215
# TODO: for now, it's just a delete+add
1216
my @diff_info_list = split(/\0/, $diff_infos);
1217
# Keep the subject line of the commit message as mediawiki comment for the revision
1218
- my $commit_msg = run_git("log --no-walk --format=\"%s\" $sha1_commit");
1218
+ my $commit_msg = run_git(qq(log --no-walk --format="%s" ${sha1_commit}));
1219
chomp($commit_msg);
1220
# Push every blob
1221
while (@diff_info_list) {
@@ -1227,7 +1227,7 @@ sub mw_push_revision {
1227
my $info = shift(@diff_info_list);
1228
my $file = shift(@diff_info_list);
1229
($mw_revision, $status) = mw_push_file($info, $file, $commit_msg, $mw_revision);
1230
- if ($status eq "non-fast-forward") {
1230
+ if ($status eq 'non-fast-forward') {
1231
# we may already have sent part of the
1232
# commit to MediaWiki, but it's too
1233
# late to cancel it. Stop the push in
@@ -1235,17 +1235,17 @@ sub mw_push_revision {
1235
# accurate error message.
1236
return error_non_fast_forward($remote);
1237
}
1238
- if ($status ne "ok") {
1238
+ if ($status ne 'ok') {
1239
die("Unknown error from mw_push_file()\n");
1240
}
1241
}
1242
unless ($dumb_push) {
1243
- run_git("notes --ref=$remotename/mediawiki add -f -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
1244
- run_git("update-ref -m \"Git-MediaWiki push\" refs/mediawiki/$remotename/master $sha1_commit $sha1_child");
1243
+ run_git(qq(notes --ref=${remotename}/mediawiki add -f -m "mediawiki_revision: ${mw_revision}" ${sha1_commit}));
1244
+ run_git(qq(update-ref -m "Git-MediaWiki push" refs/mediawiki/${remotename}/master ${sha1_commit} ${sha1_child}));
1245
}
1246
}
1247
1248
- print STDOUT "ok $remote\n";
1248
+ print STDOUT "ok ${remote}\n";
1249
return 1;
1250
}
1251
@@ -1281,8 +1281,8 @@ sub get_mw_namespace_id {
1281
# Look at configuration file, if the record for that namespace is
1282
# already cached. Namespaces are stored in form:
1283
# "Name_of_namespace:Id_namespace", ex.: "File:6".
1284
- my @temp = split(/\n/, run_git("config --get-all remote."
1285
- . $remotename .".namespaceCache"));
1284
+ my @temp = split(/\n/,
1285
+ run_git("config --get-all remote.${remotename}.namespaceCache"));
1286
chomp(@temp);
1287
foreach my $ns (@temp) {
1288
my ($n, $id) = split(/:/, $ns);
@@ -1296,7 +1296,7 @@ sub get_mw_namespace_id {
1296
}
1297
1298
if (!exists $namespace_id{$name}) {
1299
- print STDERR "Namespace $name not found in cache, querying the wiki ...\n";
1299
+ print STDERR "Namespace ${name} not found in cache, querying the wiki ...\n";
1300
# NS not found => get namespace id from MW and store it in
1301
# configuration file.
1302
my $query = {
@@ -1321,7 +1321,7 @@ sub get_mw_namespace_id {
1321
my $id;
1322
1323
unless (defined $ns) {
1324
- print STDERR "No such namespace $name on MediaWiki.\n";
1324
+ print STDERR "No such namespace ${name} on MediaWiki.\n";
1325
$ns = {is_namespace => 0};
1326
$namespace_id{$name} = $ns;
1327
}
@@ -1335,8 +1335,7 @@ sub get_mw_namespace_id {
1335
1336
# Store explicitely requested namespaces on disk
1337
if (!exists $cached_mw_namespace_id{$name}) {
1338
- run_git("config --add remote.". $remotename
1339
- .".namespaceCache \"". $name .":". $store_id ."\"");
1338
+ run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));
1339
$cached_mw_namespace_id{$name} = 1;
1340
}
1341
return $id;