jcristau avatar jcristau committed cb907cf

Add a new pushexperiment extension

This extension introduce a faster way to push obsolescence marker. Send the
obsstore directly instead of inefficiently going through pushkey's
inefficiency.

Comments (0)

Files changed (1)

hgext/pushexperiment.py

+"""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.
+
+"""
+
+import errno
+from StringIO import StringIO
+
+from mercurial.i18n import _
+from mercurial import extensions
+from mercurial import wireproto
+from mercurial import obsolete
+
+
+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'):
+        try:
+            obsfp = repo.sopener('obsstore')
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                raise
+            return
+        remote.push_experiment_pushobsmarkers_0(obsfp)
+        return
+    return orig(repo, remote)
+
+
+def capabilities(orig, repo, proto):
+    """wrapper to advertise new capability"""
+    caps = orig(repo, proto)
+    if obsolete._enabled:
+        caps += ' _push_experiment_pushobsmarkers_0'
+    return caps
+
+
+def extsetup(ui):
+    wireproto.wirepeer.push_experiment_pushobsmarkers_0 = client_pushobsmarkers
+    wireproto.commands['push_experiment_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
+    extensions.wrapfunction(wireproto, 'capabilities', capabilities)
+    extensions.wrapfunction(obsolete, 'syncpush', syncpush)
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.