git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts
We already have a check that no new revisions are on the wiki at the beginning of the push, but this didn't handle concurrent accesses to the wiki. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ac86ec0f5e
commit
3c1ed90ec3
@ -287,6 +287,9 @@ sub get_last_local_revision {
|
|||||||
return $lastrevision_number;
|
return $lastrevision_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Remember the timestamp corresponding to a revision id.
|
||||||
|
my %basetimestamps;
|
||||||
|
|
||||||
sub get_last_remote_revision {
|
sub get_last_remote_revision {
|
||||||
mw_connect_maybe();
|
mw_connect_maybe();
|
||||||
|
|
||||||
@ -300,7 +303,7 @@ sub get_last_remote_revision {
|
|||||||
my $query = {
|
my $query = {
|
||||||
action => 'query',
|
action => 'query',
|
||||||
prop => 'revisions',
|
prop => 'revisions',
|
||||||
rvprop => 'ids',
|
rvprop => 'ids|timestamp',
|
||||||
pageids => $id,
|
pageids => $id,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -308,6 +311,8 @@ sub get_last_remote_revision {
|
|||||||
|
|
||||||
my $lastrev = pop(@{$result->{query}->{pages}->{$id}->{revisions}});
|
my $lastrev = pop(@{$result->{query}->{pages}->{$id}->{revisions}});
|
||||||
|
|
||||||
|
$basetimestamps{$lastrev->{revid}} = $lastrev->{timestamp};
|
||||||
|
|
||||||
$max_rev_num = ($lastrev->{revid} > $max_rev_num ? $lastrev->{revid} : $max_rev_num);
|
$max_rev_num = ($lastrev->{revid} > $max_rev_num ? $lastrev->{revid} : $max_rev_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,18 +654,32 @@ sub mw_push_file {
|
|||||||
action => 'edit',
|
action => 'edit',
|
||||||
summary => $summary,
|
summary => $summary,
|
||||||
title => $title,
|
title => $title,
|
||||||
|
basetimestamp => $basetimestamps{$newrevid},
|
||||||
text => mediawiki_clean($file_content, $page_created),
|
text => mediawiki_clean($file_content, $page_created),
|
||||||
}, {
|
}, {
|
||||||
skip_encoding => 1 # Helps with names with accentuated characters
|
skip_encoding => 1 # Helps with names with accentuated characters
|
||||||
}) || die 'Fatal: Error ' .
|
});
|
||||||
$mediawiki->{error}->{code} .
|
if (!$result) {
|
||||||
' from mediwiki: ' . $mediawiki->{error}->{details};
|
if ($mediawiki->{error}->{code} == 3) {
|
||||||
|
# edit conflicts, considered as non-fast-forward
|
||||||
|
print STDERR 'Warning: Error ' .
|
||||||
|
$mediawiki->{error}->{code} .
|
||||||
|
' from mediwiki: ' . $mediawiki->{error}->{details} .
|
||||||
|
".\n";
|
||||||
|
return ($newrevid, "non-fast-forward");
|
||||||
|
} else {
|
||||||
|
# Other errors. Shouldn't happen => just die()
|
||||||
|
die 'Fatal: Error ' .
|
||||||
|
$mediawiki->{error}->{code} .
|
||||||
|
' from mediwiki: ' . $mediawiki->{error}->{details};
|
||||||
|
}
|
||||||
|
}
|
||||||
$newrevid = $result->{edit}->{newrevid};
|
$newrevid = $result->{edit}->{newrevid};
|
||||||
print STDERR "Pushed file: $new_sha1 - $title\n";
|
print STDERR "Pushed file: $new_sha1 - $title\n";
|
||||||
} else {
|
} else {
|
||||||
print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
|
print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
|
||||||
}
|
}
|
||||||
return $newrevid;
|
return ($newrevid, "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mw_push {
|
sub mw_push {
|
||||||
@ -767,13 +786,25 @@ sub mw_push_revision {
|
|||||||
chomp($commit_msg);
|
chomp($commit_msg);
|
||||||
# Push every blob
|
# Push every blob
|
||||||
while (@diff_info_list) {
|
while (@diff_info_list) {
|
||||||
|
my $status;
|
||||||
# git diff-tree -z gives an output like
|
# git diff-tree -z gives an output like
|
||||||
# <metadata>\0<filename1>\0
|
# <metadata>\0<filename1>\0
|
||||||
# <metadata>\0<filename2>\0
|
# <metadata>\0<filename2>\0
|
||||||
# and we've split on \0.
|
# and we've split on \0.
|
||||||
my $info = shift(@diff_info_list);
|
my $info = shift(@diff_info_list);
|
||||||
my $file = shift(@diff_info_list);
|
my $file = shift(@diff_info_list);
|
||||||
$mw_revision = mw_push_file($info, $file, $commit_msg, $mw_revision);
|
($mw_revision, $status) = mw_push_file($info, $file, $commit_msg, $mw_revision);
|
||||||
|
if ($status eq "non-fast-forward") {
|
||||||
|
# we may already have sent part of the
|
||||||
|
# commit to MediaWiki, but it's too
|
||||||
|
# late to cancel it. Stop the push in
|
||||||
|
# the middle, but still give an
|
||||||
|
# accurate error message.
|
||||||
|
return error_non_fast_forward($remote);
|
||||||
|
}
|
||||||
|
if ($status ne "ok") {
|
||||||
|
die("Unknown error from mw_push_file()");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unless ($dumb_push) {
|
unless ($dumb_push) {
|
||||||
run_git("notes --ref=$remotename/mediawiki add -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
|
run_git("notes --ref=$remotename/mediawiki add -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
|
||||||
|
Loading…
Reference in New Issue
Block a user