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