Re: [PATCH 10/18] Put long code into a submodule
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jun 7, 2013, 04:01 UTC
- Message-ID
- <CAPig+cT+H2gqVjeBvR7iZ9mKz1+H1w7kt3htKOZxWHgkfq2mNA@mail.gmail.com>
- In-Reply-To
- <1370547263-13558-11-git-send-email-celestin.matte@ensimag.fr>
On Thu, Jun 6, 2013 at 3:34 PM, Célestin Matte <celestin.matte@ensimag.fr> wrote:
Show 61 quoted lines
> Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
> ---
> contrib/mw-to-git/git-remote-mediawiki.perl | 44 ++++++++++++++++-----------
> 1 file changed, 26 insertions(+), 18 deletions(-)
>
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index 1c34ada..1271527 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -133,24 +133,7 @@ while (<STDIN>) {
> @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;
> - }
> + parse_commands();
> } else {
> # blank line: we should terminate
> last;
> @@ -168,6 +151,31 @@ sub exit_error_usage {
> die "ERROR: git-remote-mediawiki module was not called with a correct number of parameters\n";
> }
>
> +sub parse_commands {
> + 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;In the original code, 'last' lived directly in the enclosing 'while' loop, but after this patch, it is inside parse_commands(). With 'use warnings' enabled, you are going to see an "Exiting subroutine via last" diagnostic.
Show 6 quoted lines
> + } > + return; > +} > + > # MediaWiki API instance, created lazily. > my $mediawiki;