git-remote-mediawiki: extract revision-importing loop to a function

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Jul 6, 2012 at 12:03 UTC 312fa9aa122631a307d81c4ca226647e7c001ee8
1 file changed +13 -3
contrib/mw-to-git/git-remote-mediawiki
+13 -3
@@ -822,10 +822,18 @@ sub mw_import_ref {
822 @revisions = sort {$a->{revid} <=> $b->{revid}} @revisions;
823 my @revision_ids = map $_->{revid}, @revisions;
824
825 - $n = 0;
825 + return mw_import_revids($fetch_from, \@revision_ids, \%pages_hash);
826 +}
827 +
828 +sub mw_import_revids {
829 + my $fetch_from = shift;
830 + my $revision_ids = shift;
831 + my $pages = shift;
832 +
833 + my $n = 0;
834 my $last_timestamp = 0; # Placeholer in case $rev->timestamp is undefined
835
828 - foreach my $pagerevid (@revision_ids) {
836 + foreach my $pagerevid (@$revision_ids) {
837 # fetch the content of the pages
838 my $query = {
839 action => 'query',
@@ -866,7 +874,7 @@ sub mw_import_ref {
874 # If this is a revision of the media page for new version
875 # of a file do one common commit for both file and media page.
876 # Else do commit only for that page.
869 - print STDERR "$n/", scalar(@revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
877 + print STDERR "$n/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
878 import_file_revision(\%commit, ($fetch_from == 1), $n, \%mediafile);
879 }
880
@@ -876,6 +884,8 @@ sub mw_import_ref {
884 # thrown saying that HEAD is refering to unknown object 0000000000000000000
885 # and the clone fails.
886 }
887 +
888 + return $n;
889 }
890
891 sub error_non_fast_forward {