Skip to content

Commit 93f0d33

Browse files
moygitster
authored andcommitted
git-remote-mediawiki: allow push to set MediaWiki metadata
Push can not set the commit note "mediawiki_revision:" and update the remote reference. This avoids having to "git pull --rebase" after each push, and is probably more natural. Make it the default, but let it be configurable with mediawiki.dumbPush or remote.<remotename>.dumbPush. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 428c995 commit 93f0d33

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ my $shallow_import = run_git("config --get --bool remote.". $remotename .".shall
8484
chomp($shallow_import);
8585
$shallow_import = ($shallow_import eq "true");
8686

87+
# Dumb push: don't update notes and mediawiki ref to reflect the last push.
88+
#
89+
# Configurable with mediawiki.dumbPush, or per-remote with
90+
# remote.<remotename>.dumbPush.
91+
#
92+
# This means the user will have to re-import the just-pushed
93+
# revisions. On the other hand, this means that the Git revisions
94+
# corresponding to MediaWiki revisions are all imported from the wiki,
95+
# regardless of whether they were initially created in Git or from the
96+
# web interface, hence all users will get the same history (i.e. if
97+
# the push from Git to MediaWiki loses some information, everybody
98+
# will get the history with information lost). If the import is
99+
# deterministic, this means everybody gets the same sha1 for each
100+
# MediaWiki revision.
101+
my $dumb_push = run_git("config --get --bool remote.$remotename.dumbPush");
102+
unless ($dumb_push) {
103+
$dumb_push = run_git("config --get --bool mediawiki.dumbPush");
104+
}
105+
chomp($dumb_push);
106+
$dumb_push = ($dumb_push eq "true");
107+
87108
my $wiki_name = $url;
88109
$wiki_name =~ s/[^\/]*:\/\///;
89110

@@ -598,6 +619,9 @@ sub mw_push_file {
598619
my $complete_file_name = shift;
599620
# Commit message
600621
my $summary = shift;
622+
# MediaWiki revision number. Keep the previous one by default,
623+
# in case there's no edit to perform.
624+
my $newrevid = shift;
601625

602626
my $new_sha1 = $diff_info_split[3];
603627
my $old_sha1 = $diff_info_split[2];
@@ -631,10 +655,12 @@ sub mw_push_file {
631655
}) || die 'Fatal: Error ' .
632656
$mediawiki->{error}->{code} .
633657
' from mediwiki: ' . $mediawiki->{error}->{details};
658+
$newrevid = $result->{edit}->{newrevid};
634659
print STDERR "Pushed file : $new_sha1 - $title\n";
635660
} else {
636661
print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
637662
}
663+
return $newrevid;
638664
}
639665

640666
sub mw_push {
@@ -666,7 +692,7 @@ sub mw_push {
666692
# Notify Git that the push is done
667693
print STDOUT "\n";
668694

669-
if ($pushed) {
695+
if ($pushed && $dumb_push) {
670696
print STDERR "Just pushed some revisions to MediaWiki.\n";
671697
print STDERR "The pushed revisions now have to be re-imported, and your current branch\n";
672698
print STDERR "needs to be updated with these re-imported commits. You can do this with\n";
@@ -682,6 +708,7 @@ sub mw_push_revision {
682708
my $last_local_revid = get_last_local_revision();
683709
print STDERR ".\n"; # Finish sentence started by get_last_local_revision()
684710
my $last_remote_revid = get_last_remote_revision();
711+
my $mw_revision = $last_remote_revid;
685712

686713
# Get sha1 of commit pointed by local HEAD
687714
my $HEAD_sha1 = run_git("rev-parse $local 2>/dev/null"); chomp($HEAD_sha1);
@@ -747,7 +774,11 @@ sub mw_push_revision {
747774
# and we've split on \0.
748775
my $info = shift(@diff_info_list);
749776
my $file = shift(@diff_info_list);
750-
mw_push_file($info, $file, $commit_msg);
777+
$mw_revision = mw_push_file($info, $file, $commit_msg, $mw_revision);
778+
}
779+
unless ($dumb_push) {
780+
run_git("notes --ref=$remotename/mediawiki add -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
781+
run_git("update-ref -m \"Git-MediaWiki push\" refs/mediawiki/$remotename/master $sha1_commit $sha1_child");
751782
}
752783
}
753784

0 commit comments

Comments
 (0)