exchange: add the pushmarker wireproto command to simple4server
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 28 Feb 2014 00:55:34 -0800
changeset 822 5f5d269278e9
parent 821 202376586cf6
child 823 9aa20585e158
exchange: add the pushmarker wireproto command to simple4server This will allow simple server side support. (yes, code duplication is bad, I won't do it too much mom)
hgext/simple4server.py
--- a/hgext/simple4server.py	Fri Feb 28 00:40:29 2014 -0800
+++ b/hgext/simple4server.py	Fri Feb 28 00:55:34 2014 -0800
@@ -10,3 +10,36 @@
 
 import mercurial.obsolete
 mercurial.obsolete._enabled = True
+
+from mercurial import wireproto
+from mercurial import extension
+
+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 capabilities(orig, repo, proto):
+    """wrapper to advertise new capability"""
+    caps = orig(repo, proto)
+    if obsolete._enabled:
+        caps += ' _evoext_pushobsmarkers_0'
+    return caps
+
+def extsetup(ui):
+    wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
+    extensions.wrapfunction(wireproto, 'capabilities', capabilities)