summaryrefslogtreecommitdiff
path: root/contrib/mw-to-git
diff options
context:
space:
mode:
authorLibravatar Célestin Matte <celestin.matte@ensimag.fr>2013-06-14 15:50:29 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-06-14 09:02:17 -0700
commit6a316beeeecc76d19ff60fda62e00a7e2e041137 (patch)
tree20ee696d4b1980561162d14fdd59e03cd2014fef /contrib/mw-to-git
parentgit-remote-mediawiki: remove import of unused open2 (diff)
downloadtgif-6a316beeeecc76d19ff60fda62e00a7e2e041137.tar.xz
git-remote-mediawiki: put long code into a subroutine
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>
Diffstat (limited to 'contrib/mw-to-git')
-rwxr-xr-xcontrib/mw-to-git/git-remote-mediawiki.perl56
1 files changed, 32 insertions, 24 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index e3a79db425..bc31ba49fc 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -122,32 +122,10 @@ $wiki_name =~ s{[^/]*://}{};
$wiki_name =~ s/^.*@//;
# Commands parser
-my @cmd;
while (<STDIN>) {
chomp;
- @cmd = split(/ /);
- if (defined($cmd[0])) {
- # Line not blank
- if ($cmd[0] eq "capabilities") {
- die("Too many arguments for capabilities\n") if (defined($cmd[1]));
- mw_capabilities();
- } elsif ($cmd[0] eq "list") {
- die("Too many arguments for list\n") if (defined($cmd[2]));
- mw_list($cmd[1]);
- } elsif ($cmd[0] eq "import") {
- die("Invalid arguments for import\n") if ($cmd[1] eq "" || defined($cmd[2]));
- mw_import($cmd[1]);
- } elsif ($cmd[0] eq "option") {
- die("Too many arguments for option\n") if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
- mw_option($cmd[1],$cmd[2]);
- } elsif ($cmd[0] eq "push") {
- mw_push($cmd[1]);
- } else {
- print STDERR "Unknown command. Aborting...\n";
- last;
- }
- } else {
- # blank line: we should terminate
+
+ if (!parse_command($_)) {
last;
}
@@ -157,6 +135,36 @@ while (<STDIN>) {
########################## Functions ##############################
+sub parse_command {
+ my ($line) = @_;
+ my @cmd = split(/ /, $line);
+ if (!defined $cmd[0]) {
+ return 0;
+ }
+ if ($cmd[0] eq "capabilities") {
+ die("Too many arguments for capabilities\n")
+ if (defined($cmd[1]));
+ mw_capabilities();
+ } elsif ($cmd[0] eq "list") {
+ die("Too many arguments for list\n") if (defined($cmd[2]));
+ mw_list($cmd[1]);
+ } elsif ($cmd[0] eq "import") {
+ die("Invalid arguments for import\n")
+ if ($cmd[1] eq "" || defined($cmd[2]));
+ mw_import($cmd[1]);
+ } elsif ($cmd[0] eq "option") {
+ die("Too many arguments for option\n")
+ if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
+ mw_option($cmd[1],$cmd[2]);
+ } elsif ($cmd[0] eq "push") {
+ mw_push($cmd[1]);
+ } else {
+ print STDERR "Unknown command. Aborting...\n";
+ return 0;
+ }
+ return 1;
+}
+
# MediaWiki API instance, created lazily.
my $mediawiki;