Skip to content

Commit

Permalink
git-remote-mediawiki: put long code into a subroutine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Célestin Matte authored and Junio C Hamano committed Jun 14, 2013
1 parent 42e9192 commit 6a316be
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions contrib/mw-to-git/git-remote-mediawiki.perl
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,10 @@
$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;
}

Expand All @@ -157,6 +135,36 @@

########################## 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;

Expand Down

0 comments on commit 6a316be

Please sign in to comment.