[PATCH v2 20/22] git-remote-mediawiki: Put non-trivial numeric values in constants.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Signed-off-by: Matthieu Moy <matthieu.moy@xxxxxxxxxxxxxxx>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index e6dc6db..94a0411 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -43,6 +43,16 @@ Readonly my $EMPTY_MESSAGE => '*Empty MediaWiki Message*';
 
 Readonly my $EMPTY => q{};
 
+# Number of pages taken into account at once in submodule get_mw_page_list
+Readonly my $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).
+Readonly my $BATCH_SIZE => 10;
+
+Readonly my $HTTP_CODE_OK => 200;
+
 if (@ARGV != 2) {
 	exit_error_usage();
 }
@@ -226,13 +236,13 @@ sub get_mw_page_list {
 	my $pages = shift;
 	my @some_pages = @$page_list;
 	while (@some_pages) {
-		my $last_page = 50;
+		my $last_page = $SLICE_SIZE;
 		if ($#some_pages < $last_page) {
 			$last_page = $#some_pages;
 		}
 		my @slice = @some_pages[0..$last_page];
 		get_mw_first_pages(\@slice, $pages);
-		@some_pages = @some_pages[51..$#some_pages];
+		@some_pages = @some_pages[($SLICE_SIZE + 1)..$#some_pages];
 	}
 	return;
 }
@@ -388,9 +398,7 @@ sub get_linked_mediafiles {
 	my $pages = shift;
 	my @titles = map { $_->{title} } values(%{$pages});
 
-	# The query is split in small batches because of the MW API limit of
-	# the number of links to be returned (500 links max).
-	my $batch = 10;
+	my $batch = $BATCH_SIZE;
 	while (@titles) {
 		if ($#titles < $batch) {
 			$batch = $#titles;
@@ -472,7 +480,7 @@ sub download_mw_mediafile {
 	my $download_url = shift;
 
 	my $response = $mediawiki->{ua}->get($download_url);
-	if ($response->code == 200) {
+	if ($response->code == $HTTP_CODE_OK) {
 		return $response->decoded_content;
 	} else {
 		print {*STDERR} "Error downloading mediafile from :\n";
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]