git-remote-mediawiki: don't use quotes for empty strings

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Célestin Matte committed Jun 14, 2013 at 15:50 UTC aeb95eeaff625dc9d5450e180a6e7a7e024efd23
1 file changed +10 -8
contrib/mw-to-git/git-remote-mediawiki.perl
+10 -8
@@ -40,6 +40,8 @@ use constant NULL_SHA1 => '0000000000000000000000000000000000000000';
40 # Used on Git's side to reflect empty edit messages on the wiki
41 use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
42
43 +use constant EMPTY => q{};
44 +
45 my $remotename = $ARGV[0];
46 my $url = $ARGV[1];
47
@@ -150,11 +152,11 @@ sub parse_command {
152 mw_list($cmd[1]);
153 } elsif ($cmd[0] eq 'import') {
154 die("Invalid arguments for import\n")
153 - if ($cmd[1] eq "" || defined($cmd[2]));
155 + if ($cmd[1] eq EMPTY || defined($cmd[2]));
156 mw_import($cmd[1]);
157 } elsif ($cmd[0] eq 'option') {
158 die("Too many arguments for option\n")
157 - if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
159 + if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY || defined($cmd[3]));
160 mw_option($cmd[1],$cmd[2]);
161 } elsif ($cmd[0] eq 'push') {
162 mw_push($cmd[1]);
@@ -555,7 +557,7 @@ sub mediawiki_clean {
557 # Mediawiki does not allow blank space at the end of a page and ends with a single \n.
558 # This function right trims a string and adds a \n at the end to follow this rule
559 $string =~ s/\s+$//;
558 - if ($string eq "" && $page_created) {
560 + if ($string eq EMPTY && $page_created) {
561 # Creating empty pages is forbidden.
562 $string = EMPTY_CONTENT;
563 }
@@ -566,7 +568,7 @@ sub mediawiki_clean {
568 sub mediawiki_smudge {
569 my $string = shift;
570 if ($string eq EMPTY_CONTENT) {
569 - $string = "";
571 + $string = EMPTY;
572 }
573 # This \n is important. This is due to mediawiki's way to handle end of files.
574 return "${string}\n";
@@ -992,7 +994,7 @@ sub mw_upload_file {
994 } else {
995 # Don't let perl try to interpret file content as UTF-8 => use "raw"
996 my $content = run_git("cat-file blob ${new_sha1}", 'raw');
995 - if ($content ne "") {
997 + if ($content ne EMPTY) {
998 mw_connect_maybe();
999 $mediawiki->{config}->{upload_url} =
1000 "${url}/index.php/Special:Upload";
@@ -1034,7 +1036,7 @@ sub mw_push_file {
1036 my $newrevid;
1037
1038 if ($summary eq EMPTY_MESSAGE) {
1037 - $summary = '';
1039 + $summary = EMPTY;
1040 }
1041
1042 my $new_sha1 = $diff_info_split[3];
@@ -1045,7 +1047,7 @@ sub mw_push_file {
1047
1048 my ($title, $extension) = $complete_file_name =~ /^(.*)\.([^\.]*)$/;
1049 if (!defined($extension)) {
1048 - $extension = "";
1050 + $extension = EMPTY;
1051 }
1052 if ($extension eq 'mw') {
1053 my $ns = get_mw_namespace_id_for_page($complete_file_name);
@@ -1113,7 +1115,7 @@ sub mw_push {
1115 if ($force) {
1116 print {*STDERR} "Warning: forced push not allowed on a MediaWiki.\n";
1117 }
1116 - if ($local eq "") {
1118 + if ($local eq EMPTY) {
1119 print {*STDERR} "Cannot delete remote branch on a MediaWiki\n";
1120 print {*STDOUT} "error ${remote} cannot delete\n";
1121 next;