Show More
@@ -1,100 +1,101 b'' | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing 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 | return cmd != '' |
|
48 | return cmd != '' | |
48 |
|
49 | |||
49 | def do_heads(self): |
|
50 | def do_heads(self): | |
50 | h = self.repo.heads() |
|
51 | h = self.repo.heads() | |
51 | self.respond(" ".join(map(hex, h)) + "\n") |
|
52 | self.respond(" ".join(map(hex, h)) + "\n") | |
52 |
|
53 | |||
53 | def do_lock(self): |
|
54 | def do_lock(self): | |
54 | self.lock = self.repo.lock() |
|
55 | self.lock = self.repo.lock() | |
55 | self.respond("") |
|
56 | self.respond("") | |
56 |
|
57 | |||
57 | def do_unlock(self): |
|
58 | def do_unlock(self): | |
58 | if self.lock: |
|
59 | if self.lock: | |
59 | self.lock.release() |
|
60 | self.lock.release() | |
60 | self.lock = None |
|
61 | self.lock = None | |
61 | self.respond("") |
|
62 | self.respond("") | |
62 |
|
63 | |||
63 | def do_branches(self): |
|
64 | def do_branches(self): | |
64 | arg, nodes = self.getarg() |
|
65 | arg, nodes = self.getarg() | |
65 | nodes = map(bin, nodes.split(" ")) |
|
66 | nodes = map(bin, nodes.split(" ")) | |
66 | r = [] |
|
67 | r = [] | |
67 | for b in self.repo.branches(nodes): |
|
68 | for b in self.repo.branches(nodes): | |
68 | r.append(" ".join(map(hex, b)) + "\n") |
|
69 | r.append(" ".join(map(hex, b)) + "\n") | |
69 | self.respond("".join(r)) |
|
70 | self.respond("".join(r)) | |
70 |
|
71 | |||
71 | def do_between(self): |
|
72 | def do_between(self): | |
72 | arg, pairs = self.getarg() |
|
73 | arg, pairs = self.getarg() | |
73 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
74 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
74 | r = [] |
|
75 | r = [] | |
75 | for b in self.repo.between(pairs): |
|
76 | for b in self.repo.between(pairs): | |
76 | r.append(" ".join(map(hex, b)) + "\n") |
|
77 | r.append(" ".join(map(hex, b)) + "\n") | |
77 | self.respond("".join(r)) |
|
78 | self.respond("".join(r)) | |
78 |
|
79 | |||
79 | def do_changegroup(self): |
|
80 | def do_changegroup(self): | |
80 | nodes = [] |
|
81 | nodes = [] | |
81 | arg, roots = self.getarg() |
|
82 | arg, roots = self.getarg() | |
82 | nodes = map(bin, roots.split(" ")) |
|
83 | nodes = map(bin, roots.split(" ")) | |
83 |
|
84 | |||
84 | cg = self.repo.changegroup(nodes, 'serve') |
|
85 | cg = self.repo.changegroup(nodes, 'serve') | |
85 | while True: |
|
86 | while True: | |
86 | d = cg.read(4096) |
|
87 | d = cg.read(4096) | |
87 | if not d: |
|
88 | if not d: | |
88 | break |
|
89 | break | |
89 | self.fout.write(d) |
|
90 | self.fout.write(d) | |
90 |
|
91 | |||
91 | self.fout.flush() |
|
92 | self.fout.flush() | |
92 |
|
93 | |||
93 | def do_addchangegroup(self): |
|
94 | def do_addchangegroup(self): | |
94 | if not self.lock: |
|
95 | if not self.lock: | |
95 | self.respond("not locked") |
|
96 | self.respond("not locked") | |
96 | return |
|
97 | return | |
97 |
|
98 | |||
98 | self.respond("") |
|
99 | self.respond("") | |
99 | r = self.repo.addchangegroup(self.fin, 'serve') |
|
100 | r = self.repo.addchangegroup(self.fin, 'serve') | |
100 | self.respond(str(r)) |
|
101 | self.respond(str(r)) |
General Comments 0
You need to be logged in to leave comments.
Login now