git-remote-mediawiki: bugfix for pages w/ >500 revisions

Mediawiki introduces a new API for queries w/ more than 500 results in version 1.21. That change triggered an infinite loop while cloning a mediawiki with such a page. The latest API renamed and moved the "continuing" information in the response, necessary to build the next query. The code failed to retrieve that information but still detected that it was in a "continuing query". As a result, it launched the same query over and over again. If a "continuing" information is detected in the response (old or new), the next query is updated accordingly. If not, we quit assuming it's not a continuing query. Reported-by: Benjamin Cathey Signed-off-by: Benoit Person <benoit.person@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Benoit Person committed Sep 24, 2013 at 21:32 UTC 1d905f74fd2b05dcbc768acbb5426dc11fb00f6f
2 files changed +35 -2
contrib/mw-to-git/git-remote-mediawiki.perl
+12 -2
@@ -622,6 +622,9 @@ sub fetch_mw_revisions_for_page {
622 rvstartid => $fetch_from,
623 rvlimit => 500,
624 pageids => $id,
625 +
626 + # Let MediaWiki know that we support the latest API.
627 + continue => '',
628 };
629
630 my $revnum = 0;
@@ -637,8 +640,15 @@ sub fetch_mw_revisions_for_page {
640 push(@page_revs, $page_rev_ids);
641 $revnum++;
642 }
640 - last if (!$result->{'query-continue'});
641 - $query->{rvstartid} = $result->{'query-continue'}->{revisions}->{rvstartid};
643 +
644 + if ($result->{'query-continue'}) { # For legacy APIs
645 + $query->{rvstartid} = $result->{'query-continue'}->{revisions}->{rvstartid};
646 + } elsif ($result->{continue}) { # For newer APIs
647 + $query->{rvstartid} = $result->{continue}->{rvcontinue};
648 + $query->{continue} = $result->{continue}->{continue};
649 + } else {
650 + last;
651 + }
652 }
653 if ($shallow_import && @page_revs) {
654 print {*STDERR} " Found 1 revision (shallow import).\n";
contrib/mw-to-git/t/t9365-continuing-queries.sh new
+23
@@ -0,0 +1,23 @@
1 +#!/bin/sh
2 +
3 +test_description='Test the Git Mediawiki remote helper: queries w/ more than 500 results'
4 +
5 +. ./test-gitmw-lib.sh
6 +. $TEST_DIRECTORY/test-lib.sh
7 +
8 +test_check_precond
9 +
10 +test_expect_success 'creating page w/ >500 revisions' '
11 + wiki_reset &&
12 + for i in `test_seq 501`
13 + do
14 + echo "creating revision $i" &&
15 + wiki_editpage foo "revision $i<br/>" true
16 + done
17 +'
18 +
19 +test_expect_success 'cloning page w/ >500 revisions' '
20 + git clone mediawiki::'"$WIKI_URL"' mw_dir
21 +'
22 +
23 +test_done