{"thread":{"id":"28512","subject":"[PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts","startedAt":"2011-09-27T17:54:58Z","lastAt":"2011-09-28T13:48:01Z","messageCount":4,"participants":["Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"176350","messageId":"1317146100-22938-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"28512","inReplyTo":null,"subject":"[PATCH 1/3] git-remote-mediawiki: trivial fixes","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-09-27T17:54:58Z","receivedAt":"2011-09-27T17:54:58Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Fix a whitespace issue (no space before :) and remove unused %status in\nmw_push.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n contrib/mw-to-git/git-remote-mediawiki |    3 +--\n 1 files changed, 1 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex 0ba88de..768b42d 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -656,7 +656,7 @@ sub mw_push_file {\n \t\t\t\t  $mediawiki->{error}->{code} .\n \t\t\t\t  ' from mediwiki: ' . $mediawiki->{error}->{details};\n \t\t$newrevid = $result->{edit}->{newrevid};\n-\t\tprint STDERR \"Pushed file : $new_sha1 - $title\\n\";\n+\t\tprint STDERR \"Pushed file: $new_sha1 - $title\\n\";\n \t} else {\n \t\tprint STDERR \"$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\\n\"\n \t}\n@@ -666,7 +666,6 @@ sub mw_push_file {\n sub mw_push {\n \t# multiple push statements can follow each other\n \tmy @refsspecs = (shift, get_more_refs(\"push\"));\n-\tmy %status;\n \tmy $pushed;\n \tfor my $refspec (@refsspecs) {\n \t\tmy ($force, $local, $remote) = $refspec =~ /^(\\+)?([^:]*):([^:]*)$/\n-- \n1.7.7.rc0.75.g56f27\n"},{"id":"176349","messageId":"1317146100-22938-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"28512","inReplyTo":"1317146100-22938-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/3] git-remote-mediawiki: set 'basetimestamp' to let the wiki handle conflicts","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-09-27T17:54:59Z","receivedAt":"2011-09-27T17:54:59Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"We already have a check that no new revisions are on the wiki at the\nbeginning of the push, but this didn't handle concurrent accesses to the\nwiki.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n contrib/mw-to-git/git-remote-mediawiki |   43 +++++++++++++++++++++++++++----\n 1 files changed, 37 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex 768b42d..9bb58ab 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -287,6 +287,9 @@ sub get_last_local_revision {\n \treturn $lastrevision_number;\n }\n \n+# Remember the timestamp corresponding to a revision id.\n+my %basetimestamps;\n+\n sub get_last_remote_revision {\n \tmw_connect_maybe();\n \n@@ -300,7 +303,7 @@ sub get_last_remote_revision {\n \t\tmy $query = {\n \t\t\taction => 'query',\n \t\t\tprop => 'revisions',\n-\t\t\trvprop => 'ids',\n+\t\t\trvprop => 'ids|timestamp',\n \t\t\tpageids => $id,\n \t\t};\n \n@@ -308,6 +311,8 @@ sub get_last_remote_revision {\n \n \t\tmy $lastrev = pop(@{$result->{query}->{pages}->{$id}->{revisions}});\n \n+\t\t$basetimestamps{$lastrev->{revid}} = $lastrev->{timestamp};\n+\n \t\t$max_rev_num = ($lastrev->{revid} > $max_rev_num ? $lastrev->{revid} : $max_rev_num);\n \t}\n \n@@ -649,18 +654,32 @@ sub mw_push_file {\n \t\t\taction => 'edit',\n \t\t\tsummary => $summary,\n \t\t\ttitle => $title,\n+\t\t\tbasetimestamp => $basetimestamps{$newrevid},\n \t\t\ttext => mediawiki_clean($file_content, $page_created),\n \t\t\t\t  }, {\n \t\t\t\t\t  skip_encoding => 1 # Helps with names with accentuated characters\n-\t\t\t\t  }) || die 'Fatal: Error ' .\n-\t\t\t\t  $mediawiki->{error}->{code} .\n-\t\t\t\t  ' from mediwiki: ' . $mediawiki->{error}->{details};\n+\t\t\t\t  });\n+\t\tif (!$result) {\n+\t\t\tif ($mediawiki->{error}->{code} == 3) {\n+\t\t\t\t# edit conflicts, considered as non-fast-forward\n+\t\t\t\tprint STDERR 'Warning: Error ' .\n+\t\t\t\t    $mediawiki->{error}->{code} .\n+\t\t\t\t    ' from mediwiki: ' . $mediawiki->{error}->{details} .\n+\t\t\t\t    \".\\n\";\n+\t\t\t\treturn ($newrevid, \"non-fast-forward\");\n+\t\t\t} else {\n+\t\t\t\t# Other errors. Shouldn't happen => just die()\n+\t\t\t\tdie 'Fatal: Error ' .\n+\t\t\t\t    $mediawiki->{error}->{code} .\n+\t\t\t\t    ' from mediwiki: ' . $mediawiki->{error}->{details};\n+\t\t\t}\n+\t\t}\n \t\t$newrevid = $result->{edit}->{newrevid};\n \t\tprint STDERR \"Pushed file: $new_sha1 - $title\\n\";\n \t} else {\n \t\tprint STDERR \"$complete_file_name not a mediawiki file (Not pushable on this version of git-remote-mediawiki).\\n\"\n \t}\n-\treturn $newrevid;\n+\treturn ($newrevid, \"ok\");\n }\n \n sub mw_push {\n@@ -767,13 +786,25 @@ sub mw_push_revision {\n \t\tchomp($commit_msg);\n \t\t# Push every blob\n \t\twhile (@diff_info_list) {\n+\t\t\tmy $status;\n \t\t\t# git diff-tree -z gives an output like\n \t\t\t# <metadata>\\0<filename1>\\0\n \t\t\t# <metadata>\\0<filename2>\\0\n \t\t\t# and we've split on \\0.\n \t\t\tmy $info = shift(@diff_info_list);\n \t\t\tmy $file = shift(@diff_info_list);\n-\t\t\t$mw_revision = mw_push_file($info, $file, $commit_msg, $mw_revision);\n+\t\t\t($mw_revision, $status) = mw_push_file($info, $file, $commit_msg, $mw_revision);\n+\t\t\tif ($status eq \"non-fast-forward\") {\n+\t\t\t\t# we may already have sent part of the\n+\t\t\t\t# commit to MediaWiki, but it's too\n+\t\t\t\t# late to cancel it. Stop the push in\n+\t\t\t\t# the middle, but still give an\n+\t\t\t\t# accurate error message.\n+\t\t\t\treturn error_non_fast_forward($remote);\n+\t\t\t}\n+\t\t\tif ($status ne \"ok\") {\n+\t\t\t\tdie(\"Unknown error from mw_push_file()\");\n+\t\t\t}\n \t\t}\n \t\tunless ($dumb_push) {\n \t\t\trun_git(\"notes --ref=$remotename/mediawiki add -m \\\"mediawiki_revision: $mw_revision\\\" $sha1_commit\");\n-- \n1.7.7.rc0.75.g56f27\n"},{"id":"176351","messageId":"1317146100-22938-3-git-send-email-Matthieu.Moy@imag.fr","threadId":"28512","inReplyTo":"1317146100-22938-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 3/3] git-remote-mediawiki: obey advice.pushNonFastForward","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-09-27T17:55:00Z","receivedAt":"2011-09-27T17:55:00Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n contrib/mw-to-git/git-remote-mediawiki |   17 ++++++++++-------\n 1 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex 9bb58ab..b809792 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -603,13 +603,16 @@ sub mw_import_ref {\n }\n \n sub error_non_fast_forward {\n-\t# Native git-push would show this after the summary.\n-\t# We can't ask it to display it cleanly, so print it\n-\t# ourselves before.\n-\tprint STDERR \"To prevent you from losing history, non-fast-forward updates were rejected\\n\";\n-\tprint STDERR \"Merge the remote changes (e.g. 'git pull') before pushing again. See the\\n\";\n-\tprint STDERR \"'Note about fast-forwards' section of 'git push --help' for details.\\n\";\n-\n+\tmy $advice = run_git(\"config --bool advice.pushNonFastForward\");\n+\tchomp($advice);\n+\tif ($advice ne \"false\") {\n+\t\t# Native git-push would show this after the summary.\n+\t\t# We can't ask it to display it cleanly, so print it\n+\t\t# ourselves before.\n+\t\tprint STDERR \"To prevent you from losing history, non-fast-forward updates were rejected\\n\";\n+\t\tprint STDERR \"Merge the remote changes (e.g. 'git pull') before pushing again. See the\\n\";\n+\t\tprint STDERR \"'Note about fast-forwards' section of 'git push --help' for details.\\n\";\n+\t}\n \tprint STDOUT \"error $_[0] \\\"non-fast-forward\\\"\\n\";\n \treturn 0;\n }\n-- \n1.7.7.rc0.75.g56f27\n"},{"id":"176404","messageId":"1317217681-18763-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"28512","inReplyTo":"1317146100-22938-3-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH] git-remote-mediawiki: allow a domain to be set for authentication","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2011-09-28T13:48:01Z","receivedAt":"2011-09-28T13:48:01Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"When the wiki uses e.g. LDAP for authentication, the web interface shows\na popup to allow the user to chose an authentication domain, and we need\nto use lgdomain in the API at login time.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n contrib/mw-to-git/git-remote-mediawiki |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex b809792..0b32d18 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -76,8 +76,10 @@ my $wiki_login = run_git(\"config --get remote.\". $remotename .\".mwLogin\");\n # inside a remote helper, so our stdin is connect to git, not to a\n # terminal.\n my $wiki_passwd = run_git(\"config --get remote.\". $remotename .\".mwPassword\");\n+my $wiki_domain = run_git(\"config --get remote.\". $remotename .\".mwDomain\");\n chomp($wiki_login);\n chomp($wiki_passwd);\n+chomp($wiki_domain);\n \n # Import only last revisions (both for clone and fetch)\n my $shallow_import = run_git(\"config --get --bool remote.\". $remotename .\".shallow\");\n@@ -158,6 +160,7 @@ sub mw_connect_maybe {\n \t\tif (!$mediawiki->login({\n \t\t\tlgname => $wiki_login,\n \t\t\tlgpassword => $wiki_passwd,\n+\t\t\tlgdomain => $wiki_domain,\n \t\t})) {\n \t\t\tprint STDERR \"Failed to log in mediawiki user \\\"$wiki_login\\\" on $url\\n\";\n \t\t\tprint STDERR \"(error \" .\n-- \n1.7.7.rc0.75.g56f27\n"}]}