git-remote-mediawiki: refactor loop over revision ids
Without changing the behavior, we turn the foreach loop on an array of revisions into a loop on an array of integer. It will be easier to implement other strategies as they will only need to produce an array of integer instead of a more complex data-structure. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
b1ede9a9f2
commit
4465b6d610
@ -819,30 +819,35 @@ sub mw_import_ref {
|
||||
# Creation of the fast-import stream
|
||||
print STDERR "Fetching & writing export data...\n";
|
||||
|
||||
@revisions = sort {$a->{revid} <=> $b->{revid}} @revisions;
|
||||
my @revision_ids = map $_->{revid}, @revisions;
|
||||
|
||||
$n = 0;
|
||||
my $last_timestamp = 0; # Placeholer in case $rev->timestamp is undefined
|
||||
|
||||
foreach my $pagerevid (sort {$a->{revid} <=> $b->{revid}} @revisions) {
|
||||
foreach my $pagerevid (@revision_ids) {
|
||||
# fetch the content of the pages
|
||||
my $query = {
|
||||
action => 'query',
|
||||
prop => 'revisions',
|
||||
rvprop => 'content|timestamp|comment|user|ids',
|
||||
revids => $pagerevid->{revid},
|
||||
revids => $pagerevid,
|
||||
};
|
||||
|
||||
my $result = $mediawiki->api($query);
|
||||
|
||||
my $rev = pop(@{$result->{query}->{pages}->{$pagerevid->{pageid}}->{revisions}});
|
||||
my @result_pages = values(%{$result->{query}->{pages}});
|
||||
my $result_page = $result_pages[0];
|
||||
my $rev = $result_pages[0]->{revisions}->[0];
|
||||
|
||||
$n++;
|
||||
|
||||
my $page_title = $result->{query}->{pages}->{$pagerevid->{pageid}}->{title};
|
||||
my $page_title = $result_page->{title};
|
||||
my %commit;
|
||||
$commit{author} = $rev->{user} || 'Anonymous';
|
||||
$commit{comment} = $rev->{comment} || '*Empty MediaWiki Message*';
|
||||
$commit{title} = mediawiki_smudge_filename($page_title);
|
||||
$commit{mw_revision} = $pagerevid->{revid};
|
||||
$commit{mw_revision} = $rev->{revid};
|
||||
$commit{content} = mediawiki_smudge($rev->{'*'});
|
||||
|
||||
if (!defined($rev->{timestamp})) {
|
||||
@ -861,7 +866,7 @@ sub mw_import_ref {
|
||||
# If this is a revision of the media page for new version
|
||||
# of a file do one common commit for both file and media page.
|
||||
# Else do commit only for that page.
|
||||
print STDERR "$n/", scalar(@revisions), ": Revision #$pagerevid->{revid} of $commit{title}\n";
|
||||
print STDERR "$n/", scalar(@revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
|
||||
import_file_revision(\%commit, ($fetch_from == 1), $n, \%mediafile);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user