pushkey: add ssh support
authorMatt Mackall <mpm@selenic.com>
Wed, 16 Jun 2010 16:05:13 -0500
changeset 11369 02a4373ca5cd
parent 11368 b9eb005c54ad
child 11370 db3f6f0e4e7d
pushkey: add ssh support
mercurial/sshrepo.py
mercurial/sshserver.py
--- a/mercurial/sshrepo.py	Wed Jun 16 16:04:46 2010 -0500
+++ b/mercurial/sshrepo.py	Wed Jun 16 16:05:13 2010 -0500
@@ -273,4 +273,21 @@
     def stream_out(self):
         return self.do_cmd('stream_out')
 
+    def pushkey(self, namespace, key, old, new):
+        if not self.capable('pushkey'):
+            return False
+        d = self.call("pushkey",
+                      namespace=namespace, key=key, old=old, new=new)
+        return bool(int(d))
+
+    def listkeys(self, namespace):
+        if not self.capable('pushkey'):
+            return {}
+        d = self.call("listkeys", namespace=namespace)
+        r = {}
+        for l in d.splitlines():
+            k, v = l.split('\t')
+            r[k.decode('string-escape')] = v.decode('string-escape')
+        return r
+
 instance = sshrepository
--- a/mercurial/sshserver.py	Wed Jun 16 16:04:46 2010 -0500
+++ b/mercurial/sshserver.py	Wed Jun 16 16:05:13 2010 -0500
@@ -8,12 +8,12 @@
 
 from i18n import _
 from node import bin, hex
-import streamclone, util, hook
+import streamclone, util, hook, pushkey
 import os, sys, tempfile, urllib, copy
 
 class sshserver(object):
 
-    caps = 'unbundle lookup changegroupsubset branchmap'.split()
+    caps = 'unbundle lookup changegroupsubset branchmap pushkey'.split()
 
     def __init__(self, ui, repo):
         self.ui = ui
@@ -223,3 +223,18 @@
         except streamclone.StreamException, inst:
             self.fout.write(str(inst))
             self.fout.flush()
+
+    def do_pushkey(self):
+        arg, key = self.getarg()
+        arg, namespace = self.getarg()
+        arg, new = self.getarg()
+        arg, old = self.getarg()
+        r = pushkey.push(self.repo, namespace, key, old, new)
+        self.respond('%s\n' % int(r))
+
+    def do_listkeys(self):
+        arg, namespace = self.getarg()
+        d = pushkey.list(self.repo, namespace).items()
+        t = '\n'.join(['%s\t%s' % (k.encode('string-escape'),
+                                   v.encode('string-escape')) for k, v in d])
+        self.respond(t)