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