From: Junio C Hamano Date: Sun, 23 Jun 2013 21:53:13 +0000 (-0700) Subject: Merge branch 'cm/remote-mediawiki-perlcritique' X-Git-Tag: v1.8.4-rc0~147 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39abbd38d82104e3873af478e7ba509fca3e08af;p=thirdparty%2Fgit.git Merge branch 'cm/remote-mediawiki-perlcritique' * cm/remote-mediawiki-perlcritique: (31 commits) git-remote-mediawiki: make error message more precise git-remote-mediawiki: add a perlcritic rule in Makefile git-remote-mediawiki: add a .perlcriticrc file git-remote-mediawiki: clearly rewrite double dereference git-remote-mediawiki: fix a typo ("mediwiki" instead of "mediawiki") git-remote-mediawiki: put non-trivial numeric values in constants. git-remote-mediawiki: don't use quotes for empty strings git-remote-mediawiki: replace "unless" statements with negated "if" statements git-remote-mediawiki: brace file handles for print for more clarity git-remote-mediawiki: modify strings for a better coding-style git-remote-mediawiki: put long code into a subroutine git-remote-mediawiki: remove import of unused open2 git-remote-mediawiki: check return value of open git-remote-mediawiki: assign a variable as undef and make proper indentation git-remote-mediawiki: rename a variable ($last) which has the name of a keyword git-remote-mediawiki: remove unused variable $entry git-remote-mediawiki: turn double-negated expressions into simple expressions git-remote-mediawiki: change the name of a variable git-remote-mediawiki: add newline in the end of die() error messages git-remote-mediawiki: change style in a regexp ... --- 39abbd38d82104e3873af478e7ba509fca3e08af diff --cc contrib/mw-to-git/git-remote-mediawiki.perl index c1a967b3d1,9ff45fd926..71baf8ace8 --- a/contrib/mw-to-git/git-remote-mediawiki.perl +++ b/contrib/mw-to-git/git-remote-mediawiki.perl @@@ -42,10 -40,18 +40,22 @@@ use constant NULL_SHA1 => '000000000000 # Used on Git's side to reflect empty edit messages on the wiki use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*'; + use constant EMPTY => q{}; + + # Number of pages taken into account at once in submodule get_mw_page_list + use constant SLICE_SIZE => 50; + + # Number of linked mediafile to get at once in get_linked_mediafiles + # The query is split in small batches because of the MW API limit of + # the number of links to be returned (500 links max). + use constant BATCH_SIZE => 10; + + use constant HTTP_CODE_OK => 200; + +if (@ARGV != 2) { + exit_error_usage(); +} + my $remotename = $ARGV[0]; my $url = $ARGV[1]; @@@ -161,17 -147,40 +151,51 @@@ while () ########################## Functions ############################## +## error handling +sub exit_error_usage { + die "ERROR: git-remote-mediawiki module was not called with a correct number of\n" . + "parameters\n" . + "You may obtain this error because you attempted to run the git-remote-mediawiki\n" . + "module directly.\n" . + "This module can be used the following way:\n" . + "\tgit clone mediawiki://
\n" . + "Then, use git commit, push and pull as with every normal git repository.\n"; +} + + 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 argument for import\n") + if ($cmd[1] eq EMPTY); + die("Too many arguments for import\n") + if (defined($cmd[2])); + mw_import($cmd[1]); + } elsif ($cmd[0] eq 'option') { + die("Invalid arguments for option\n") + if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY); + die("Too many arguments for option\n") + if (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;