##// END OF EJS Templates
Initial implementation of hello command for ssh
Matt Mackall -
r2419:b17eebc9 default
parent child Browse files
Show More
@@ -1,101 +1,113 b''
1 1 # sshserver.py - ssh protocol server support for mercurial
2 2 #
3 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from demandload import demandload
9 9 from i18n import gettext as _
10 10 from node import *
11 11 demandload(globals(), "sys util")
12 12
13 13 class sshserver(object):
14 14 def __init__(self, ui, repo):
15 15 self.ui = ui
16 16 self.repo = repo
17 17 self.lock = None
18 18 self.fin = sys.stdin
19 19 self.fout = sys.stdout
20 20
21 21 sys.stdout = sys.stderr
22 22
23 23 # Prevent insertion/deletion of CRs
24 24 util.set_binary(self.fin)
25 25 util.set_binary(self.fout)
26 26
27 27 def getarg(self):
28 28 argline = self.fin.readline()[:-1]
29 29 arg, l = argline.split()
30 30 val = self.fin.read(int(l))
31 31 return arg, val
32 32
33 33 def respond(self, v):
34 34 self.fout.write("%d\n" % len(v))
35 35 self.fout.write(v)
36 36 self.fout.flush()
37 37
38 38 def serve_forever(self):
39 39 while self.serve_one(): pass
40 40 sys.exit(0)
41 41
42 42 def serve_one(self):
43 43 cmd = self.fin.readline()[:-1]
44 44 if cmd:
45 45 impl = getattr(self, 'do_' + cmd, None)
46 46 if impl: impl()
47 47 else: self.respond("")
48 48 return cmd != ''
49 49
50 50 def do_heads(self):
51 51 h = self.repo.heads()
52 52 self.respond(" ".join(map(hex, h)) + "\n")
53 53
54 def do_hello(self):
55 '''the hello command returns a set of lines describing various
56 interesting things about the server, in an RFC822-like format.
57 Currently the only one defined is "capabilities", which
58 consists of a line in the form:
59
60 capabilities: space separated list of tokens
61 '''
62
63 r = "capabilities:\n"
64 self.respond(r)
65
54 66 def do_lock(self):
55 67 self.lock = self.repo.lock()
56 68 self.respond("")
57 69
58 70 def do_unlock(self):
59 71 if self.lock:
60 72 self.lock.release()
61 73 self.lock = None
62 74 self.respond("")
63 75
64 76 def do_branches(self):
65 77 arg, nodes = self.getarg()
66 78 nodes = map(bin, nodes.split(" "))
67 79 r = []
68 80 for b in self.repo.branches(nodes):
69 81 r.append(" ".join(map(hex, b)) + "\n")
70 82 self.respond("".join(r))
71 83
72 84 def do_between(self):
73 85 arg, pairs = self.getarg()
74 86 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")]
75 87 r = []
76 88 for b in self.repo.between(pairs):
77 89 r.append(" ".join(map(hex, b)) + "\n")
78 90 self.respond("".join(r))
79 91
80 92 def do_changegroup(self):
81 93 nodes = []
82 94 arg, roots = self.getarg()
83 95 nodes = map(bin, roots.split(" "))
84 96
85 97 cg = self.repo.changegroup(nodes, 'serve')
86 98 while True:
87 99 d = cg.read(4096)
88 100 if not d:
89 101 break
90 102 self.fout.write(d)
91 103
92 104 self.fout.flush()
93 105
94 106 def do_addchangegroup(self):
95 107 if not self.lock:
96 108 self.respond("not locked")
97 109 return
98 110
99 111 self.respond("")
100 112 r = self.repo.addchangegroup(self.fin, 'serve')
101 113 self.respond(str(r))
General Comments 0
You need to be logged in to leave comments. Login now