git-remote-mediawiki: put non-trivial numeric values in constants.

Non-trivial numeric values (e.g., different from 0, 1 and 2) are placed in constants at the top of the code to be easily modifiable and to make more sense 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>

Célestin Matte committed Jun 14, 2013 at 15:50 UTC fed56c06ae86f671e3319c6d60130ed4802137f1
1 file changed +14 -6
contrib/mw-to-git/git-remote-mediawiki.perl
+14 -6
@@ -42,6 +42,16 @@ use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
42
43 use constant EMPTY => q{};
44
45 +# Number of pages taken into account at once in submodule get_mw_page_list
46 +use constant SLICE_SIZE => 50;
47 +
48 +# Number of linked mediafile to get at once in get_linked_mediafiles
49 +# The query is split in small batches because of the MW API limit of
50 +# the number of links to be returned (500 links max).
51 +use constant BATCH_SIZE => 10;
52 +
53 +use constant HTTP_CODE_OK => 200;
54 +
55 my $remotename = $ARGV[0];
56 my $url = $ARGV[1];
57
@@ -229,13 +239,13 @@ sub get_mw_page_list {
239 my $pages = shift;
240 my @some_pages = @$page_list;
241 while (@some_pages) {
232 - my $last_page = 50;
242 + my $last_page = SLICE_SIZE;
243 if ($#some_pages < $last_page) {
244 $last_page = $#some_pages;
245 }
246 my @slice = @some_pages[0..$last_page];
247 get_mw_first_pages(\@slice, $pages);
238 - @some_pages = @some_pages[51..$#some_pages];
248 + @some_pages = @some_pages[(SLICE_SIZE + 1)..$#some_pages];
249 }
250 return;
251 }
@@ -385,9 +395,7 @@ sub get_linked_mediafiles {
395 my $pages = shift;
396 my @titles = map { $_->{title} } values(%{$pages});
397
388 - # The query is split in small batches because of the MW API limit of
389 - # the number of links to be returned (500 links max).
390 - my $batch = 10;
398 + my $batch = BATCH_SIZE;
399 while (@titles) {
400 if ($#titles < $batch) {
401 $batch = $#titles;
@@ -469,7 +477,7 @@ sub download_mw_mediafile {
477 my $download_url = shift;
478
479 my $response = $mediawiki->{ua}->get($download_url);
472 - if ($response->code == 200) {
480 + if ($response->code == HTTP_CODE_OK) {
481 return $response->decoded_content;
482 } else {
483 print {*STDERR} "Error downloading mediafile from :\n";