diff options
author | Matthieu Moy <Matthieu.Moy@imag.fr> | 2012-07-06 12:03:12 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-07-06 12:20:46 -0700 |
commit | 4465b6d6101173481eb5a4b7de6bda97ea03dc19 (patch) | |
tree | badca37d6ce8dbf256676d8d327ddaa64917bc0c /contrib | |
parent | b1ede9a9f232b1416d1487bba3f69a8e88ec75ee (diff) | |
download | git-4465b6d6101173481eb5a4b7de6bda97ea03dc19.tar.gz git-4465b6d6101173481eb5a4b7de6bda97ea03dc19.tar.xz |
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>
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/mw-to-git/git-remote-mediawiki | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki index 4bf990bd5..47dd574dd 100755 --- a/contrib/mw-to-git/git-remote-mediawiki +++ b/contrib/mw-to-git/git-remote-mediawiki @@ -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); } |