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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Sep 1, 2011 at 18:54 UTC 93f0d33818e94464a581209b4a102dac59db202a
1 file changed +33 -2
contrib/mw-to-git/git-remote-mediawiki
+33 -2
@@ -84,6 +84,27 @@ my $shallow_import = run_git("config --get --bool remote.". $remotename .".shall
84 chomp($shallow_import);
85 $shallow_import = ($shallow_import eq "true");
86
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 +
108 my $wiki_name = $url;
109 $wiki_name =~ s/[^\/]*:\/\///;
110
@@ -598,6 +619,9 @@ sub mw_push_file {
619 my $complete_file_name = shift;
620 # Commit message
621 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;
625
626 my $new_sha1 = $diff_info_split[3];
627 my $old_sha1 = $diff_info_split[2];
@@ -631,10 +655,12 @@ sub mw_push_file {
655 }) || die 'Fatal: Error ' .
656 $mediawiki->{error}->{code} .
657 ' from mediwiki: ' . $mediawiki->{error}->{details};
658 + $newrevid = $result->{edit}->{newrevid};
659 print STDERR "Pushed file : $new_sha1 - $title\n";
660 } else {
661 print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
662 }
663 + return $newrevid;
664 }
665
666 sub mw_push {
@@ -666,7 +692,7 @@ sub mw_push {
692 # Notify Git that the push is done
693 print STDOUT "\n";
694
669 - if ($pushed) {
695 + if ($pushed && $dumb_push) {
696 print STDERR "Just pushed some revisions to MediaWiki.\n";
697 print STDERR "The pushed revisions now have to be re-imported, and your current branch\n";
698 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 {
708 my $last_local_revid = get_last_local_revision();
709 print STDERR ".\n"; # Finish sentence started by get_last_local_revision()
710 my $last_remote_revid = get_last_remote_revision();
711 + my $mw_revision = $last_remote_revid;
712
713 # Get sha1 of commit pointed by local HEAD
714 my $HEAD_sha1 = run_git("rev-parse $local 2>/dev/null"); chomp($HEAD_sha1);
@@ -747,7 +774,11 @@ sub mw_push_revision {
774 # and we've split on \0.
775 my $info = shift(@diff_info_list);
776 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");
782 }
783 }
784