From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Subject: [PATCH v6 21/31] git-remote-mediawiki: Put long code into a subroutine Date: Fri, 14 Jun 2013 15:50:29 +0200 Message-ID: <1371217839-23017-22-git-send-email-celestin.matte@ensimag.fr> References: <1371217839-23017-1-git-send-email-celestin.matte@ensimag.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: benoit.person@ensimag.fr, matthieu.moy@grenoble-inp.fr, =?UTF-8?q?C=C3=A9lestin=20Matte?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Jun 14 15:52:09 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UnUQ8-0001n8-Ss for gcvg-git-2@plane.gmane.org; Fri, 14 Jun 2013 15:52:05 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753154Ab3FNNvx convert rfc822-to-quoted-printable (ORCPT ); Fri, 14 Jun 2013 09:51:53 -0400 Received: from mx1.imag.fr ([129.88.30.5]:44565 "EHLO shiva.imag.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752961Ab3FNNvB (ORCPT ); Fri, 14 Jun 2013 09:51:01 -0400 Received: from ensimag.imag.fr (ensimag.imag.fr [195.221.228.12]) by shiva.imag.fr (8.13.8/8.13.8) with ESMTP id r5EDowjI020669 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 14 Jun 2013 15:50:58 +0200 Received: from ensibm.imag.fr (ensibm.imag.fr [195.221.228.8]) by ensimag.imag.fr (8.13.8/8.13.8/ImagV2.1.r_ens) with ESMTP id r5EDp00N013413; Fri, 14 Jun 2013 15:51:00 +0200 Received: from tohwi-K50IE.imag.fr (ensibm [195.221.228.8]) by ensibm.imag.fr (8.13.8/8.13.8/ImagV2.1.sb_ens.pm) with ESMTP id r5EDoqgD016142; Fri, 14 Jun 2013 15:50:59 +0200 X-Mailer: git-send-email 1.8.3.1.491.g8a51f1c In-Reply-To: <1371217839-23017-1-git-send-email-celestin.matte@ensimag.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0.1 (shiva.imag.fr [129.88.30.5]); Fri, 14 Jun 2013 15:50:58 +0200 (CEST) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: =46rom: C=C3=A9lestin Matte Signed-off-by: C=C3=A9lestin Matte Signed-off-by: Matthieu Moy --- contrib/mw-to-git/git-remote-mediawiki.perl | 56 ++++++++++++++++-----= -------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-t= o-git/git-remote-mediawiki.perl index e3a79db..bc31ba4 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 =3D~ s{[^/]*://}{}; $wiki_name =3D~ s/^.*@//; =20 # Commands parser -my @cmd; while () { chomp; - @cmd =3D 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; } =20 @@ -157,6 +135,36 @@ while () { =20 ########################## Functions ############################## =20 +sub parse_command { + my ($line) =3D @_; + my @cmd =3D 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; =20 --=20 1.8.3.rc3.49.g4e74807