merge stable into default
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 03 Jun 2013 15:06:18 +0200
changeset 730 ea629193a25e
parent 729 2e46caeb2890 (diff)
parent 725 235a942eba3f (current diff)
child 731 63ce4384be50
merge stable into default
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext/pushexperiment.py	Mon Jun 03 15:06:18 2013 +0200
@@ -0,0 +1,110 @@
+"""Small extension altering some push behavior
+
+- Add a new wire protocol command to exchange obsolescence marker. Sending the
+  raw file as a binary instead of using pushkey hack.
+- Add a "push done" notification
+- Push obsolescence marker before anything else (This work arround the lack global transaction)
+
+"""
+
+import errno
+from StringIO import StringIO
+
+from mercurial.i18n import _
+from mercurial import extensions
+from mercurial import wireproto
+from mercurial import obsolete
+from mercurial import localrepo
+
+
+def client_pushobsmarkers(self, obsfile):
+    """wireprotocol peer method"""
+    self.requirecap('_push_experiment_pushobsmarkers_0',
+                    _('push obsolete markers faster'))
+    ret, output = self._callpush('push_experiment_pushobsmarkers_0', obsfile)
+    for l in output.splitlines(True):
+        self.ui.status(_('remote: '), l)
+    return ret
+
+
+def srv_pushobsmarkers(repo, proto):
+    """wireprotocol command"""
+    fp = StringIO()
+    proto.redirect()
+    proto.getfile(fp)
+    data = fp.getvalue()
+    fp.close()
+    lock = repo.lock()
+    try:
+        tr = repo.transaction('pushkey: obsolete markers')
+        try:
+            repo.obsstore.mergemarkers(tr, data)
+            tr.close()
+        finally:
+            tr.release()
+    finally:
+        lock.release()
+    return wireproto.pushres(0)
+
+
+def syncpush(orig, repo, remote):
+    """wraper for obsolete.syncpush to use the fast way if possible"""
+    if not (obsolete._enabled and repo.obsstore):
+        return
+    if remote.capable('_push_experiment_pushobsmarkers_0'):
+        return # already pushed before changeset
+        remote.push_experiment_pushobsmarkers_0(obsfp)
+        return
+    return orig(repo, remote)
+
+
+def client_notifypushend(self):
+    """wire peer  command to notify a push is done"""
+    self.requirecap('_push_experiment_notifypushend_0', _('hook once push is all done'))
+    return self._call('push_experiment_notifypushend_0')
+
+
+def srv_notifypushend(repo, proto):
+    """wire protocol command to notify a push is done"""
+    proto.redirect()
+    repo.hook('notifypushend')
+    return wireproto.pushres(0)
+
+
+def augmented_push(orig, repo, remote, *args, **kwargs):
+    """push wrapped that call the wire protocol command"""
+    if (obsolete._enabled and repo.obsstore
+        and remote.capable('_push_experiment_pushobsmarkers_0')):
+        # push marker early to limit damage of pushing too early.
+        try:
+            obsfp = repo.sopener('obsstore')
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                raise
+        else:
+            remote.push_experiment_pushobsmarkers_0(obsfp)
+    ret = orig(repo, remote, *args, **kwargs)
+    if remote.capable('_push_experiment_notifypushend_0'):
+        remote.push_experiment_notifypushend_0()
+    return ret
+
+
+def capabilities(orig, repo, proto):
+    """wrapper to advertise new capability"""
+    caps = orig(repo, proto)
+    if obsolete._enabled:
+        caps += ' _push_experiment_pushobsmarkers_0'
+    caps += ' _push_experiment_notifypushend_0'
+    return caps
+
+
+def extsetup(ui):
+    wireproto.wirepeer.push_experiment_pushobsmarkers_0 = client_pushobsmarkers
+    wireproto.wirepeer.push_experiment_notifypushend_0 = client_notifypushend
+    wireproto.commands['push_experiment_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
+    wireproto.commands['push_experiment_notifypushend_0'] = (srv_notifypushend, '')
+    extensions.wrapfunction(wireproto, 'capabilities', capabilities)
+    extensions.wrapfunction(obsolete, 'syncpush', syncpush)
+    extensions.wrapfunction(localrepo.localrepository, 'push', augmented_push)
+
+
--- a/tests/test-evolve.t	Fri May 31 15:10:34 2013 +0200
+++ b/tests/test-evolve.t	Mon Jun 03 15:06:18 2013 +0200
@@ -313,7 +313,7 @@
   recreate:[8] another feature that rox
   atop:[7] another feature
   computing new diff
-  commited as 53ff506edef1
+  commited as d3c9b3a5c458
   $ hg glog
   @  9	feature-B: bumped update to 5f4744038ed5: - test
   |
--- a/tests/test-stabilize-result.t	Fri May 31 15:10:34 2013 +0200
+++ b/tests/test-stabilize-result.t	Mon Jun 03 15:06:18 2013 +0200
@@ -157,9 +157,9 @@
   atop:[8] newer a
   rebasing to destination parent: e8cc1b534401
   computing new diff
-  commited as eeeb8f6e7648
+  commited as 503ef784bae6
   $ glog
-  @  14:eeeb8f6e7648@default(draft) bk:[] bumped update to e3183e9c0961:
+  @  14:503ef784bae6@default(draft) bk:[] bumped update to e3183e9c0961:
   |
   | o  9:355c5cda4de1@default(draft) bk:[] add c
   | |
@@ -188,7 +188,7 @@
   $ glog
   @  15:7391601a4bfa@default(draft) bk:[] More addition
   |
-  | o  14:eeeb8f6e7648@default(draft) bk:[] bumped update to e3183e9c0961:
+  | o  14:503ef784bae6@default(draft) bk:[] bumped update to e3183e9c0961:
   | |
   o |  9:355c5cda4de1@default(draft) bk:[] add c
   | |
@@ -214,7 +214,7 @@
   |
   | o  17:4754d61bc2db@default(draft) bk:[] More addition
   |/
-  | o  14:eeeb8f6e7648@default(draft) bk:[] bumped update to e3183e9c0961:
+  | o  14:503ef784bae6@default(draft) bk:[] bumped update to e3183e9c0961:
   | |
   o |  9:355c5cda4de1@default(draft) bk:[] add c
   | |
@@ -249,7 +249,7 @@
   $ glog
   @  22:ac6d600735a4@default(draft) bk:[] More addition
   |
-  | o  14:eeeb8f6e7648@default(draft) bk:[] bumped update to e3183e9c0961:
+  | o  14:503ef784bae6@default(draft) bk:[] bumped update to e3183e9c0961:
   | |
   o |  9:355c5cda4de1@default(draft) bk:[] add c
   | |
@@ -269,6 +269,7 @@
   # HG changeset patch
   # User test
   # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
   # Node ID ac6d600735a49ee377e29d1f74a0576e8c972e7b
   # Parent  355c5cda4de162658ed9f961a98a73a10b3167b1
   More addition
--- a/tests/test-tutorial.t	Fri May 31 15:10:34 2013 +0200
+++ b/tests/test-tutorial.t	Mon Jun 03 15:06:18 2013 +0200
@@ -128,6 +128,7 @@
   # HG changeset patch
   # User test
   # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
   # Node ID d85de4546133030c82d257bbcdd9b1b416d0c31c
   # Parent  4d5dc81870237d492284826e21840b2ca00e26d1
   adding fruit
@@ -184,6 +185,7 @@
   # HG changeset patch
   # User test
   # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
   # Node ID 9d0363b81950646bc6ad1ec5de8b8197ea586541
   # Parent  4d5dc81870237d492284826e21840b2ca00e26d1
   adding fruit
@@ -365,6 +367,7 @@
   # HG changeset patch
   # User test
   # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
   # Node ID a224f2a4fb9f9f828f608959912229d7b38b26de
   # Parent  41aff6a42b7578ec7ec3cb2041633f1ca43cca96
   SPAM SPAM