git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/12] git-remote-mediawiki: refactor loop over revision ids

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 6, 2012, 10:03 UTC
Message-ID
<1341568995-12467-10-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1341568995-12467-1-git-send-email-Matthieu.Moy@imag.fr>

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>
---
 contrib/mw-to-git/git-remote-mediawiki | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index 4bf990b..47dd574 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);
 	}
 
-- 
1.7.11.1.147.g47a574d
Previous: Matthieu MoyNext: Matthieu Moy
Message 15 of 30 in “git-remote-mediawiki: tests and optimizations”
  1. 00/12 git-remote-mediawiki: tests and optimizationsMatthieu Moy, Jul 5, 2012
  2. 01/12 git-remote-mediawiki: scripts to install, delete and clear a MediaWikiMatthieu Moy, Jul 5, 2012
  3. 02/12 git-remote-mediawiki: test environment of git-remote-mediawikiMatthieu Moy, Jul 5, 2012
  4. Junio C HamanoJul 5, 2012
  5. Matthieu MoyJul 6, 2012
  6. 00/12 git-remote-mediawiki: tests and optimizationsMatthieu Moy, Jul 6, 2012
  7. 01/12 git-remote-mediawiki: scripts to install, delete and clear a MediaWikiMatthieu Moy, Jul 6, 2012
  8. 02/12 git-remote-mediawiki: test environment of git-remote-mediawikiMatthieu Moy, Jul 6, 2012
  9. 03/12 git-remote-mediawiki (t9360): test git-remote-mediawiki cloneMatthieu Moy, Jul 6, 2012
  10. 04/12 git-remote-mediawiki (t9361): test git-remote-mediawiki pull and pushMatthieu Moy, Jul 6, 2012
  11. 05/12 git-remote-mediawiki (t9362): test git-remote-mediawiki with UTF8 charactersMatthieu Moy, Jul 6, 2012
  12. 06/12 git-remote-mediawiki: support for uploading file in test environmentMatthieu Moy, Jul 6, 2012
  13. 07/12 git-remote-mediawiki (t9363): test 'File:' import and exportMatthieu Moy, Jul 6, 2012
  14. 08/12 git-remote-mediawiki: change return type of get_mw_pagesMatthieu Moy, Jul 6, 2012
  15. 09/12 git-remote-mediawiki: refactor loop over revision idsMatthieu Moy, Jul 6, 2012
  16. 10/12 git-remote-mediawiki: extract revision-importing loop to a functionMatthieu Moy, Jul 6, 2012
  17. 11/12 git-remote-mediawiki: more efficient 'pull' in the best caseMatthieu Moy, Jul 6, 2012
  18. 12/12 git-remote-mediawiki: be more defensive when requests failMatthieu Moy, Jul 6, 2012
  19. 03/12 git-remote-mediawiki (t9360): test git-remote-mediawiki cloneMatthieu Moy, Jul 5, 2012
  20. 04/12 git-remote-mediawiki (t9361): test git-remote-mediawiki pull and pushMatthieu Moy, Jul 5, 2012
  21. Junio C HamanoJul 5, 2012
  22. 05/12 git-remote-mediawiki (t9362): test git-remote-mediawiki with UTF8 charactersMatthieu Moy, Jul 5, 2012
  23. 06/12 git-remote-mediawiki: support for uploading file in test environmentMatthieu Moy, Jul 5, 2012
  24. 07/12 git-remote-mediawiki (t9363): test 'File:' import and exportMatthieu Moy, Jul 5, 2012
  25. 08/12 git-remote-mediawiki: change return type of get_mw_pagesMatthieu Moy, Jul 5, 2012
  26. Junio C HamanoJul 5, 2012
  27. 09/12 git-remote-mediawiki: refactor loop over revision idsMatthieu Moy, Jul 5, 2012
  28. 10/12 git-remote-mediawiki: extract revision-importing loop to a functionMatthieu Moy, Jul 5, 2012
  29. 11/12 git-remote-mediawiki: more efficient 'pull' in the best caseMatthieu Moy, Jul 5, 2012
  30. 12/12 git-remote-mediawiki: be more defensive when requests failMatthieu Moy, Jul 5, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.