[PATCH 2 of 4] schemas: add wireproto implementations of schema passing

Durham Goode durham at fb.com
Tue Aug 6 19:28:27 CDT 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1375827497 25200
#      Tue Aug 06 15:18:17 2013 -0700
# Node ID ef29e2e8de0198d5041f60e9cbfc7b5a29fea93d
# Parent  f6fca02b697a67bec6e6ca2c9a48d7c7d7f1d077
schemas: add wireproto implementations of schema passing

This adds the wire protocol logic for requesting and transmitting
schema data. It is transmitted as a series of lines:
"%s %s\n" % (schema name, url)

'*' is used as the args for the api in case we want to change the signature
later.

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -293,6 +293,19 @@
         f = self._callstream("getbundle", **opts)
         return changegroupmod.unbundle10(self._decompress(f), 'UN')
 
+    @batchable
+    def schemas(self):
+        f = future()
+        yield {}, f
+        d = f.value
+        lines = d.splitlines()
+        schemas = {}
+        for line in lines:
+            key, value = line.split(' ', 1)
+            schemas[key] = value
+
+        yield schemas
+
     def unbundle(self, cg, heads, source):
         '''Send cg (a readable file-like object representing the
         changegroup to push, typically a chunkbuffer object) to the
@@ -525,6 +538,13 @@
                      encoding.tolocal(old), new)
     return '%s\n' % int(r)
 
+def schemas(repo, proto, others):
+    schemas = repo.schemas
+    serialized = ""
+    for k, v in schemas.iteritems():
+        serialized += "%s %s\n" % (k, v)
+    return serialized
+
 def _allowstream(ui):
     return ui.configbool('server', 'uncompressed', True, untrusted=True)
 
@@ -660,6 +680,7 @@
     'listkeys': (listkeys, 'namespace'),
     'lookup': (lookup, 'key'),
     'pushkey': (pushkey, 'namespace key old new'),
+    'schemas' : (schemas, '*'),
     'stream_out': (stream, ''),
     'unbundle': (unbundle, 'heads'),
 }


More information about the Mercurial-devel mailing list