hgext/pushexperiment.py
changeset 728 5d368ae3d5a0
parent 727 cb907cf3b556
child 729 2e46caeb2890
--- a/hgext/pushexperiment.py	Mon Jun 03 14:53:24 2013 +0200
+++ b/hgext/pushexperiment.py	Mon Jun 03 14:57:39 2013 +0200
@@ -2,6 +2,7 @@
 
 - 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
 
 """
 
@@ -12,6 +13,7 @@
 from mercurial import extensions
 from mercurial import wireproto
 from mercurial import obsolete
+from mercurial import localrepo
 
 
 def client_pushobsmarkers(self, obsfile):
@@ -60,18 +62,43 @@
     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 notifiedpush(orig, repo, remote, *args, **kwargs):
+    """push wrapped that call the wire protocol command"""
+    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', notifiedpush)