Show More
@@ -0,0 +1,100 b'' | |||||
|
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)) |
@@ -13,7 +13,7 b' demandload(globals(), "fancyopts ui hg u' | |||||
13 | demandload(globals(), "fnmatch mdiff random signal tempfile time") |
|
13 | demandload(globals(), "fnmatch mdiff random signal tempfile time") | |
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") | |
15 | demandload(globals(), "archival changegroup") |
|
15 | demandload(globals(), "archival changegroup") | |
16 | demandload(globals(), "hgweb.server") |
|
16 | demandload(globals(), "hgweb.server sshserver") | |
17 |
|
17 | |||
18 | class UnknownCommand(Exception): |
|
18 | class UnknownCommand(Exception): | |
19 | """Exception raised if command is not in the command table.""" |
|
19 | """Exception raised if command is not in the command table.""" | |
@@ -2452,76 +2452,8 b' def serve(ui, repo, **opts):' | |||||
2452 | if opts["stdio"]: |
|
2452 | if opts["stdio"]: | |
2453 | if repo is None: |
|
2453 | if repo is None: | |
2454 | raise hg.RepoError(_('no repo found')) |
|
2454 | raise hg.RepoError(_('no repo found')) | |
2455 | fin, fout = sys.stdin, sys.stdout |
|
2455 | s = sshserver.sshserver(ui, repo) | |
2456 | sys.stdout = sys.stderr |
|
2456 | s.serve_forever() | |
2457 |
|
||||
2458 | # Prevent insertion/deletion of CRs |
|
|||
2459 | util.set_binary(fin) |
|
|||
2460 | util.set_binary(fout) |
|
|||
2461 |
|
||||
2462 | def getarg(): |
|
|||
2463 | argline = fin.readline()[:-1] |
|
|||
2464 | arg, l = argline.split() |
|
|||
2465 | val = fin.read(int(l)) |
|
|||
2466 | return arg, val |
|
|||
2467 | def respond(v): |
|
|||
2468 | fout.write("%d\n" % len(v)) |
|
|||
2469 | fout.write(v) |
|
|||
2470 | fout.flush() |
|
|||
2471 |
|
||||
2472 | lock = None |
|
|||
2473 |
|
||||
2474 | while 1: |
|
|||
2475 | cmd = fin.readline()[:-1] |
|
|||
2476 | if cmd == '': |
|
|||
2477 | return |
|
|||
2478 | if cmd == "heads": |
|
|||
2479 | h = repo.heads() |
|
|||
2480 | respond(" ".join(map(hex, h)) + "\n") |
|
|||
2481 | if cmd == "lock": |
|
|||
2482 | lock = repo.lock() |
|
|||
2483 | respond("") |
|
|||
2484 | if cmd == "unlock": |
|
|||
2485 | if lock: |
|
|||
2486 | lock.release() |
|
|||
2487 | lock = None |
|
|||
2488 | respond("") |
|
|||
2489 | elif cmd == "branches": |
|
|||
2490 | arg, nodes = getarg() |
|
|||
2491 | nodes = map(bin, nodes.split(" ")) |
|
|||
2492 | r = [] |
|
|||
2493 | for b in repo.branches(nodes): |
|
|||
2494 | r.append(" ".join(map(hex, b)) + "\n") |
|
|||
2495 | respond("".join(r)) |
|
|||
2496 | elif cmd == "between": |
|
|||
2497 | arg, pairs = getarg() |
|
|||
2498 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
|||
2499 | r = [] |
|
|||
2500 | for b in repo.between(pairs): |
|
|||
2501 | r.append(" ".join(map(hex, b)) + "\n") |
|
|||
2502 | respond("".join(r)) |
|
|||
2503 | elif cmd == "changegroup": |
|
|||
2504 | nodes = [] |
|
|||
2505 | arg, roots = getarg() |
|
|||
2506 | nodes = map(bin, roots.split(" ")) |
|
|||
2507 |
|
||||
2508 | cg = repo.changegroup(nodes, 'serve') |
|
|||
2509 | while 1: |
|
|||
2510 | d = cg.read(4096) |
|
|||
2511 | if not d: |
|
|||
2512 | break |
|
|||
2513 | fout.write(d) |
|
|||
2514 |
|
||||
2515 | fout.flush() |
|
|||
2516 |
|
||||
2517 | elif cmd == "addchangegroup": |
|
|||
2518 | if not lock: |
|
|||
2519 | respond("not locked") |
|
|||
2520 | continue |
|
|||
2521 | respond("") |
|
|||
2522 |
|
||||
2523 | r = repo.addchangegroup(fin, 'serve') |
|
|||
2524 | respond(str(r)) |
|
|||
2525 |
|
2457 | |||
2526 | optlist = ("name templates style address port ipv6" |
|
2458 | optlist = ("name templates style address port ipv6" | |
2527 | " accesslog errorlog webdir_conf") |
|
2459 | " accesslog errorlog webdir_conf") |
General Comments 0
You need to be logged in to leave comments.
Login now