Skip to content

Commit 1d905f7

Browse files
bpersonjrn
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent a0d3f10 commit 1d905f7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

contrib/mw-to-git/git-remote-mediawiki.perl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ sub fetch_mw_revisions_for_page {
622622
rvstartid => $fetch_from,
623623
rvlimit => 500,
624624
pageids => $id,
625+
626+
# Let MediaWiki know that we support the latest API.
627+
continue => '',
625628
};
626629

627630
my $revnum = 0;
@@ -637,8 +640,15 @@ sub fetch_mw_revisions_for_page {
637640
push(@page_revs, $page_rev_ids);
638641
$revnum++;
639642
}
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+
}
642652
}
643653
if ($shallow_import && @page_revs) {
644654
print {*STDERR} " Found 1 revision (shallow import).\n";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)