diff mercurial/wireproto.py @ 13723:e615765fdcc7

wireproto: add known([id]) function known([Node]) -> [1/0] Returns 1/0 for each node, indicating whether it's known by the server. Needed for new discovery protocols introduced in later patches.
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Tue, 22 Mar 2011 09:22:21 +0100
parents f4a85acef50c
children 378522bdc059
line wrap: on
line diff
--- a/mercurial/wireproto.py	Tue Mar 22 07:40:02 2011 +0100
+++ b/mercurial/wireproto.py	Tue Mar 22 09:22:21 2011 +0100
@@ -40,6 +40,14 @@
         except:
             self._abort(error.ResponseError(_("unexpected response:"), d))
 
+    def known(self, nodes):
+        n = encodelist(nodes)
+        d = self._call("known", nodes=n)
+        try:
+            return [bool(int(f)) for f in d]
+        except:
+            self._abort(error.ResponseError(_("unexpected response:"), d))
+
     def branchmap(self):
         d = self._call("branchmap")
         try:
@@ -198,7 +206,7 @@
     return "".join(r)
 
 def capabilities(repo, proto):
-    caps = 'lookup changegroupsubset branchmap pushkey'.split()
+    caps = 'lookup changegroupsubset branchmap pushkey known'.split()
     if _allowstream(repo.ui):
         requiredformats = repo.requirements & repo.supportedformats
         # if our local revlogs are just revlogv1, add 'stream' cap
@@ -255,6 +263,9 @@
         success = 0
     return "%s %s\n" % (success, r)
 
+def known(repo, proto, nodes):
+    return ''.join(b and "1" or "0" for b in repo.known(decodelist(nodes)))
+
 def pushkey(repo, proto, namespace, key, old, new):
     # compatibility with pre-1.8 clients which were accidentally
     # sending raw binary nodes rather than utf-8-encoded hex
@@ -373,6 +384,7 @@
     'debugwireargs': (debugwireargs, 'one two *'),
     'heads': (heads, ''),
     'hello': (hello, ''),
+    'known': (known, 'nodes'),
     'listkeys': (listkeys, 'namespace'),
     'lookup': (lookup, 'key'),
     'pushkey': (pushkey, 'namespace key old new'),