Mercurial > public > mercurial-scm > hg
comparison mercurial/sshserver.py @ 11580:69248b5add46
protocol: move most ssh responses to returns
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Jul 2010 15:25:15 -0500 |
parents | c19d7e91cc46 |
children | 4530b3307fb9 |
comparison
equal
deleted
inserted
replaced
11579:c19d7e91cc46 | 11580:69248b5add46 |
---|---|
70 def serve_one(self): | 70 def serve_one(self): |
71 cmd = self.fin.readline()[:-1] | 71 cmd = self.fin.readline()[:-1] |
72 if cmd: | 72 if cmd: |
73 impl = getattr(self, 'do_' + cmd, None) | 73 impl = getattr(self, 'do_' + cmd, None) |
74 if impl: | 74 if impl: |
75 impl() | 75 r = impl() |
76 if r is not None: | |
77 self.respond(r) | |
76 else: self.respond("") | 78 else: self.respond("") |
77 return cmd != '' | 79 return cmd != '' |
78 | 80 |
79 def do_lookup(self): | 81 def do_lookup(self): |
80 key = self.getarg('key') | 82 key = self.getarg('key') |
82 r = hex(self.repo.lookup(key)) | 84 r = hex(self.repo.lookup(key)) |
83 success = 1 | 85 success = 1 |
84 except Exception, inst: | 86 except Exception, inst: |
85 r = str(inst) | 87 r = str(inst) |
86 success = 0 | 88 success = 0 |
87 self.respond("%s %s\n" % (success, r)) | 89 return "%s %s\n" % (success, r) |
88 | 90 |
89 def do_branchmap(self): | 91 def do_branchmap(self): |
90 branchmap = self.repo.branchmap() | 92 branchmap = self.repo.branchmap() |
91 heads = [] | 93 heads = [] |
92 for branch, nodes in branchmap.iteritems(): | 94 for branch, nodes in branchmap.iteritems(): |
93 branchname = urllib.quote(branch) | 95 branchname = urllib.quote(branch) |
94 branchnodes = [hex(node) for node in nodes] | 96 branchnodes = [hex(node) for node in nodes] |
95 heads.append('%s %s' % (branchname, ' '.join(branchnodes))) | 97 heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
96 self.respond('\n'.join(heads)) | 98 return '\n'.join(heads) |
97 | 99 |
98 def do_heads(self): | 100 def do_heads(self): |
99 h = self.repo.heads() | 101 h = self.repo.heads() |
100 self.respond(" ".join(map(hex, h)) + "\n") | 102 return " ".join(map(hex, h)) + "\n" |
101 | 103 |
102 def do_hello(self): | 104 def do_hello(self): |
103 '''the hello command returns a set of lines describing various | 105 '''the hello command returns a set of lines describing various |
104 interesting things about the server, in an RFC822-like format. | 106 interesting things about the server, in an RFC822-like format. |
105 Currently the only one defined is "capabilities", which | 107 Currently the only one defined is "capabilities", which |
108 capabilities: space separated list of tokens | 110 capabilities: space separated list of tokens |
109 ''' | 111 ''' |
110 caps = copy.copy(self.caps) | 112 caps = copy.copy(self.caps) |
111 if streamclone.allowed(self.repo.ui): | 113 if streamclone.allowed(self.repo.ui): |
112 caps.append('stream=%d' % self.repo.changelog.version) | 114 caps.append('stream=%d' % self.repo.changelog.version) |
113 self.respond("capabilities: %s\n" % (' '.join(caps),)) | 115 return "capabilities: %s\n" % (' '.join(caps),) |
114 | 116 |
115 def do_lock(self): | 117 def do_lock(self): |
116 '''DEPRECATED - allowing remote client to lock repo is not safe''' | 118 '''DEPRECATED - allowing remote client to lock repo is not safe''' |
117 | 119 |
118 self.lock = self.repo.lock() | 120 self.lock = self.repo.lock() |
119 self.respond("") | 121 return "" |
120 | 122 |
121 def do_unlock(self): | 123 def do_unlock(self): |
122 '''DEPRECATED''' | 124 '''DEPRECATED''' |
123 | 125 |
124 if self.lock: | 126 if self.lock: |
125 self.lock.release() | 127 self.lock.release() |
126 self.lock = None | 128 self.lock = None |
127 self.respond("") | 129 return "" |
128 | 130 |
129 def do_branches(self): | 131 def do_branches(self): |
130 nodes = self.getarg('nodes') | 132 nodes = self.getarg('nodes') |
131 nodes = map(bin, nodes.split(" ")) | 133 nodes = map(bin, nodes.split(" ")) |
132 r = [] | 134 r = [] |
133 for b in self.repo.branches(nodes): | 135 for b in self.repo.branches(nodes): |
134 r.append(" ".join(map(hex, b)) + "\n") | 136 r.append(" ".join(map(hex, b)) + "\n") |
135 self.respond("".join(r)) | 137 return "".join(r) |
136 | 138 |
137 def do_between(self): | 139 def do_between(self): |
138 pairs = self.getarg('pairs') | 140 pairs = self.getarg('pairs') |
139 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | 141 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
140 r = [] | 142 r = [] |
141 for b in self.repo.between(pairs): | 143 for b in self.repo.between(pairs): |
142 r.append(" ".join(map(hex, b)) + "\n") | 144 r.append(" ".join(map(hex, b)) + "\n") |
143 self.respond("".join(r)) | 145 return "".join(r) |
144 | 146 |
145 def do_changegroup(self): | 147 def do_changegroup(self): |
146 nodes = [] | 148 nodes = [] |
147 roots = self.getarg('roots') | 149 roots = self.getarg('roots') |
148 nodes = map(bin, roots.split(" ")) | 150 nodes = map(bin, roots.split(" ")) |
178 return | 180 return |
179 | 181 |
180 self.respond("") | 182 self.respond("") |
181 r = self.repo.addchangegroup(self.fin, 'serve', self.client_url(), | 183 r = self.repo.addchangegroup(self.fin, 'serve', self.client_url(), |
182 lock=self.lock) | 184 lock=self.lock) |
183 self.respond(str(r)) | 185 return str(r) |
184 | 186 |
185 def client_url(self): | 187 def client_url(self): |
186 client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0] | 188 client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0] |
187 return 'remote:ssh:' + client | 189 return 'remote:ssh:' + client |
188 | 190 |
244 self.fout.flush() | 246 self.fout.flush() |
245 | 247 |
246 def do_pushkey(self): | 248 def do_pushkey(self): |
247 namespace, key, old, new = self.getargs('namespace key old new') | 249 namespace, key, old, new = self.getargs('namespace key old new') |
248 r = pushkey.push(self.repo, namespace, key, old, new) | 250 r = pushkey.push(self.repo, namespace, key, old, new) |
249 self.respond('%s\n' % int(r)) | 251 return '%s\n' % int(r) |
250 | 252 |
251 def do_listkeys(self): | 253 def do_listkeys(self): |
252 namespace = self.getarg('namespace') | 254 namespace = self.getarg('namespace') |
253 d = pushkey.list(self.repo, namespace).items() | 255 d = pushkey.list(self.repo, namespace).items() |
254 t = '\n'.join(['%s\t%s' % (k.encode('string-escape'), | 256 t = '\n'.join(['%s\t%s' % (k.encode('string-escape'), |
255 v.encode('string-escape')) for k, v in d]) | 257 v.encode('string-escape')) for k, v in d]) |
256 self.respond(t) | 258 return t |