git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] git-remote-mediawiki: trivial fixes
@ 2011-09-27 17:54 Matthieu Moy
  2011-09-27 17:54 ` [PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts Matthieu Moy
  2011-09-27 17:55 ` [PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward Matthieu Moy
  0 siblings, 2 replies; 4+ messages in thread
From: Matthieu Moy @ 2011-09-27 17:54 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

Fix a whitespace issue (no space before :) and remove unused %status in
mw_push.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 contrib/mw-to-git/git-remote-mediawiki |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index 0ba88de..768b42d 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -656,7 +656,7 @@ sub mw_push_file {
 				  $mediawiki->{error}->{code} .
 				  ' from mediwiki: ' . $mediawiki->{error}->{details};
 		$newrevid = $result->{edit}->{newrevid};
-		print STDERR "Pushed file : $new_sha1 - $title\n";
+		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"
 	}
@@ -666,7 +666,6 @@ sub mw_push_file {
 sub mw_push {
 	# multiple push statements can follow each other
 	my @refsspecs = (shift, get_more_refs("push"));
-	my %status;
 	my $pushed;
 	for my $refspec (@refsspecs) {
 		my ($force, $local, $remote) = $refspec =~ /^(\+)?([^:]*):([^:]*)$/
-- 
1.7.7.rc0.75.g56f27

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts
  2011-09-27 17:54 [PATCH 1/3] git-remote-mediawiki: trivial fixes Matthieu Moy
@ 2011-09-27 17:54 ` Matthieu Moy
  2011-09-27 17:55 ` [PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward Matthieu Moy
  1 sibling, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2011-09-27 17:54 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

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>
---
 contrib/mw-to-git/git-remote-mediawiki |   43 +++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index 768b42d..9bb58ab 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -287,6 +287,9 @@ sub get_last_local_revision {
 	return $lastrevision_number;
 }
 
+# Remember the timestamp corresponding to a revision id.
+my %basetimestamps;
+
 sub get_last_remote_revision {
 	mw_connect_maybe();
 
@@ -300,7 +303,7 @@ sub get_last_remote_revision {
 		my $query = {
 			action => 'query',
 			prop => 'revisions',
-			rvprop => 'ids',
+			rvprop => 'ids|timestamp',
 			pageids => $id,
 		};
 
@@ -308,6 +311,8 @@ sub get_last_remote_revision {
 
 		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);
 	}
 
@@ -649,18 +654,32 @@ sub mw_push_file {
 			action => 'edit',
 			summary => $summary,
 			title => $title,
+			basetimestamp => $basetimestamps{$newrevid},
 			text => mediawiki_clean($file_content, $page_created),
 				  }, {
 					  skip_encoding => 1 # Helps with names with accentuated characters
-				  }) || die 'Fatal: Error ' .
-				  $mediawiki->{error}->{code} .
-				  ' from mediwiki: ' . $mediawiki->{error}->{details};
+				  });
+		if (!$result) {
+			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};
 		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;
+	return ($newrevid, "ok");
 }
 
 sub mw_push {
@@ -767,13 +786,25 @@ sub mw_push_revision {
 		chomp($commit_msg);
 		# Push every blob
 		while (@diff_info_list) {
+			my $status;
 			# git diff-tree -z gives an output like
 			# <metadata>\0<filename1>\0
 			# <metadata>\0<filename2>\0
 			# and we've split on \0.
 			my $info = 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) {
 			run_git("notes --ref=$remotename/mediawiki add -m \"mediawiki_revision: $mw_revision\" $sha1_commit");
-- 
1.7.7.rc0.75.g56f27

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward
  2011-09-27 17:54 [PATCH 1/3] git-remote-mediawiki: trivial fixes Matthieu Moy
  2011-09-27 17:54 ` [PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts Matthieu Moy
@ 2011-09-27 17:55 ` Matthieu Moy
  2011-09-28 13:48   ` [PATCH] git-remote-mediawiki: allow a domain to be set for authentication Matthieu Moy
  1 sibling, 1 reply; 4+ messages in thread
From: Matthieu Moy @ 2011-09-27 17:55 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy


Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 contrib/mw-to-git/git-remote-mediawiki |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index 9bb58ab..b809792 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -603,13 +603,16 @@ sub mw_import_ref {
 }
 
 sub error_non_fast_forward {
-	# Native git-push would show this after the summary.
-	# We can't ask it to display it cleanly, so print it
-	# ourselves before.
-	print STDERR "To prevent you from losing history, non-fast-forward updates were rejected\n";
-	print STDERR "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
-	print STDERR "'Note about fast-forwards' section of 'git push --help' for details.\n";
-
+	my $advice = run_git("config --bool advice.pushNonFastForward");
+	chomp($advice);
+	if ($advice ne "false") {
+		# Native git-push would show this after the summary.
+		# We can't ask it to display it cleanly, so print it
+		# ourselves before.
+		print STDERR "To prevent you from losing history, non-fast-forward updates were rejected\n";
+		print STDERR "Merge the remote changes (e.g. 'git pull') before pushing again. See the\n";
+		print STDERR "'Note about fast-forwards' section of 'git push --help' for details.\n";
+	}
 	print STDOUT "error $_[0] \"non-fast-forward\"\n";
 	return 0;
 }
-- 
1.7.7.rc0.75.g56f27

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] git-remote-mediawiki: allow a domain to be set for authentication
  2011-09-27 17:55 ` [PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward Matthieu Moy
@ 2011-09-28 13:48   ` Matthieu Moy
  0 siblings, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2011-09-28 13:48 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

When the wiki uses e.g. LDAP for authentication, the web interface shows
a popup to allow the user to chose an authentication domain, and we need
to use lgdomain in the API at login time.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 contrib/mw-to-git/git-remote-mediawiki |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index b809792..0b32d18 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -76,8 +76,10 @@ my $wiki_login = run_git("config --get remote.". $remotename .".mwLogin");
 # inside a remote helper, so our stdin is connect to git, not to a
 # terminal.
 my $wiki_passwd = run_git("config --get remote.". $remotename .".mwPassword");
+my $wiki_domain = run_git("config --get remote.". $remotename .".mwDomain");
 chomp($wiki_login);
 chomp($wiki_passwd);
+chomp($wiki_domain);
 
 # Import only last revisions (both for clone and fetch)
 my $shallow_import = run_git("config --get --bool remote.". $remotename .".shallow");
@@ -158,6 +160,7 @@ sub mw_connect_maybe {
 		if (!$mediawiki->login({
 			lgname => $wiki_login,
 			lgpassword => $wiki_passwd,
+			lgdomain => $wiki_domain,
 		})) {
 			print STDERR "Failed to log in mediawiki user \"$wiki_login\" on $url\n";
 			print STDERR "(error " .
-- 
1.7.7.rc0.75.g56f27

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-28 13:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-27 17:54 [PATCH 1/3] git-remote-mediawiki: trivial fixes Matthieu Moy
2011-09-27 17:54 ` [PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts Matthieu Moy
2011-09-27 17:55 ` [PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward Matthieu Moy
2011-09-28 13:48   ` [PATCH] git-remote-mediawiki: allow a domain to be set for authentication Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).