git-remote-mediawiki: change the name of a variable
[gitweb.git] / contrib / mw-to-git / git-remote-mediawiki.perl
index 5e0083304094d7658701910410cf05b55bf06c8f..1fcdf2db305ea7d93d624801c401f0899ac7d188 100755 (executable)
 $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
        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]);
@@ -247,7 +247,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;
                }
@@ -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;
        }
@@ -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;
@@ -761,12 +761,12 @@ 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;
                } 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";
                }
@@ -1167,12 +1167,12 @@ 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 ]+)/) {
-                               foreach my $parent (split(' ', $parents)) {
+                       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]+)/) {
-                               die "Unexpected output from git rev-list: $line";
+                       } elsif (!$line =~ /^([a-f0-9]+)/) {
+                               die "Unexpected output from git rev-list: $line\n";
                        }
                }
                while ($parsed_sha1 ne $HEAD_sha1) {
@@ -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);
                }
        }
@@ -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) {
@@ -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) {