git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git-remote-mediawiki: allow push to set MediaWiki metadata

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Sep 1, 2011, 16:54 UTC
Message-ID
<1314896096-17544-3-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1314896096-17544-1-git-send-email-Matthieu.Moy@imag.fr>

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>
---
 contrib/mw-to-git/git-remote-mediawiki |   35 ++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index d4d1198..0ba88de 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -84,6 +84,27 @@ my $shallow_import = run_git("config --get --bool remote.". $remotename .".shall
 chomp($shallow_import);
 $shallow_import = ($shallow_import eq "true");
 
+# Dumb push: don't update notes and mediawiki ref to reflect the last push.
+#
+# Configurable with mediawiki.dumbPush, or per-remote with
+# remote.<remotename>.dumbPush.
+#
+# This means the user will have to re-import the just-pushed
+# revisions. On the other hand, this means that the Git revisions
+# corresponding to MediaWiki revisions are all imported from the wiki,
+# regardless of whether they were initially created in Git or from the
+# web interface, hence all users will get the same history (i.e. if
+# the push from Git to MediaWiki loses some information, everybody
+# will get the history with information lost). If the import is
+# deterministic, this means everybody gets the same sha1 for each
+# MediaWiki revision.
+my $dumb_push = run_git("config --get --bool remote.$remotename.dumbPush");
+unless ($dumb_push) {
+	$dumb_push = run_git("config --get --bool mediawiki.dumbPush");
+}
+chomp($dumb_push);
+$dumb_push = ($dumb_push eq "true");
+
 my $wiki_name = $url;
 $wiki_name =~ s/[^\/]*:\/\///;
 
@@ -598,6 +619,9 @@ sub mw_push_file {
 	my $complete_file_name = shift;
 	# Commit message
 	my $summary = shift;
+	# MediaWiki revision number. Keep the previous one by default,
+	# in case there's no edit to perform.
+	my $newrevid = shift;
 
 	my $new_sha1 = $diff_info_split[3];
 	my $old_sha1 = $diff_info_split[2];
@@ -631,10 +655,12 @@ sub mw_push_file {
 				  }) || die 'Fatal: Error ' .
 				  $mediawiki->{error}->{code} .
 				  ' from mediwiki: ' . $mediawiki->{error}->{details};
+		$newrevid = $result->{edit}->{newrevid};
 		print STDERR "Pushed file : $new_sha1 - $title\n";
 	} else {
 		print STDERR "$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\n"
 	}
+	return $newrevid;
 }
 
 sub mw_push {
@@ -666,7 +692,7 @@ sub mw_push {
 	# Notify Git that the push is done
 	print STDOUT "\n";
 
-	if ($pushed) {
+	if ($pushed && $dumb_push) {
 		print STDERR "Just pushed some revisions to MediaWiki.\n";
 		print STDERR "The pushed revisions now have to be re-imported, and your current branch\n";
 		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 {
 	my $last_local_revid = get_last_local_revision();
 	print STDERR ".\n"; # Finish sentence started by get_last_local_revision()
 	my $last_remote_revid = get_last_remote_revision();
+	my $mw_revision = $last_remote_revid;
 
 	# Get sha1 of commit pointed by local HEAD
 	my $HEAD_sha1 = run_git("rev-parse $local 2>/dev/null"); chomp($HEAD_sha1);
@@ -747,7 +774,11 @@ sub mw_push_revision {
 			# and we've split on \0.
 			my $info = shift(@diff_info_list);
 			my $file = shift(@diff_info_list);
-			mw_push_file($info, $file, $commit_msg);
+			$mw_revision = mw_push_file($info, $file, $commit_msg, $mw_revision);
+		}
+		unless ($dumb_push) {
+			run_git("notes --ref=$remotename/mediawiki add -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
+			run_git("update-ref -m \"Git-MediaWiki push\" refs/mediawiki/$remotename/master $sha1_commit $sha1_child");
 		}
 	}
 
-- 
1.7.7.rc0.75.g56f27
Previous: Matthieu MoyNext: Matthieu Moy
Message 36 of 43 in “fast-import: initialize variable require_explicit_termination”
  1. 1/2 fast-import: initialize variable require_explicit_terminationMatthieu Moy, Aug 26, 2011
  2. 2/2 Add a remote helper to interact with mediawiki (fetch & push)Matthieu Moy, Aug 26, 2011
  3. Junio C HamanoAug 26, 2011
  4. Sverre RabbelierAug 29, 2011
  5. Junio C HamanoAug 29, 2011
  6. Sverre RabbelierAug 29, 2011
  7. Jonathan NiederAug 30, 2011
  8. Junio C HamanoAug 30, 2011
  9. Matthieu MoyAug 31, 2011
  10. Jonathan NiederSep 1, 2011
  11. done feature in remote-helpers (was Re: [PATCH 2/2] Add a remote helper to interact with mediawiki (fetch & push))Matthieu Moy, Aug 31, 2011
  12. Sverre RabbelierAug 31, 2011
  13. Matthieu MoyAug 31, 2011
  14. Sverre RabbelierAug 31, 2011
  15. Matthieu MoyAug 31, 2011
  16. Sverre RabbelierAug 31, 2011
  17. git-remote-helpers.txt: explain how import works with multiple refsMatthieu Moy, Aug 31, 2011
  18. (short) documentation for the testgit remote helperMatthieu Moy, Aug 31, 2011
  19. Sverre RabbelierSep 1, 2011
  20. Matthieu MoySep 1, 2011
  21. 1/2 Documentation/git-remote-helpers: explain how import works with multiple refsMatthieu Moy, Sep 1, 2011
  22. 2/2 (short) documentation for the testgit remote helperMatthieu Moy, Sep 1, 2011
  23. Sverre RabbelierSep 1, 2011
  24. Sverre RabbelierSep 1, 2011
  25. Sverre RabbelierSep 1, 2011
  26. Jonathan NiederSep 1, 2011
  27. Matthieu MoySep 3, 2011
  28. Add a remote helper to interact with mediawiki (fetch & push)Matthieu Moy, Aug 26, 2011
  29. Add a remote helper to interact with mediawiki (fetch & push)Matthieu Moy, Aug 31, 2011
  30. Sverre RabbelierAug 31, 2011
  31. Matthieu MoyAug 31, 2011
  32. Junio C HamanoSep 1, 2011
  33. Matthieu MoySep 1, 2011
  34. 0/2 Git-MediaWikiMatthieu Moy, Sep 1, 2011
  35. 1/2 Add a remote helper to interact with mediawiki (fetch & push)Matthieu Moy, Sep 1, 2011
  36. 2/2 git-remote-mediawiki: allow push to set MediaWiki metadataMatthieu Moy, Sep 1, 2011
  37. Clean termination of remote-helpers (was Re: [PATCH 2/2] Add a remote helper to interact with mediawiki (fetch & push))Matthieu Moy, Aug 31, 2011
  38. Sverre RabbelierAug 31, 2011
  39. Matthieu MoyAug 31, 2011
  40. Sverre RabbelierAug 31, 2011
  41. Junio C HamanoAug 26, 2011
  42. Matthieu MoyAug 26, 2011
  43. Junio C HamanoAug 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.