Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 11584:1af96b090116
protocol: unify changegroup commands
- add sendchangegroup protocol helpers
- handle commands with None results
- move changegroup commands into wireproto.py
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Jul 2010 15:43:20 -0500 |
parents | 944c23762c3c |
children | 5d907fbb9703 |
comparison
equal
deleted
inserted
replaced
11583:944c23762c3c | 11584:1af96b090116 |
---|---|
13 def dispatch(repo, proto, command): | 13 def dispatch(repo, proto, command): |
14 if command not in commands: | 14 if command not in commands: |
15 return False | 15 return False |
16 func, spec = commands[command] | 16 func, spec = commands[command] |
17 args = proto.getargs(spec) | 17 args = proto.getargs(spec) |
18 proto.respond(func(repo, proto, *args)) | 18 r = func(repo, proto, *args) |
19 if r != None: | |
20 proto.respond(r) | |
19 return True | 21 return True |
20 | 22 |
21 def between(repo, proto, pairs): | 23 def between(repo, proto, pairs): |
22 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | 24 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
23 r = [] | 25 r = [] |
38 nodes = map(bin, nodes.split(" ")) | 40 nodes = map(bin, nodes.split(" ")) |
39 r = [] | 41 r = [] |
40 for b in repo.branches(nodes): | 42 for b in repo.branches(nodes): |
41 r.append(" ".join(map(hex, b)) + "\n") | 43 r.append(" ".join(map(hex, b)) + "\n") |
42 return "".join(r) | 44 return "".join(r) |
45 | |
46 def changegroup(repo, proto, roots): | |
47 nodes = map(bin, roots.split(" ")) | |
48 cg = repo.changegroup(nodes, 'serve') | |
49 proto.sendchangegroup(cg) | |
50 | |
51 def changegroupsubset(repo, proto, bases, heads): | |
52 bases = [bin(n) for n in bases.split(' ')] | |
53 heads = [bin(n) for n in heads.split(' ')] | |
54 cg = repo.changegroupsubset(bases, heads, 'serve') | |
55 proto.sendchangegroup(cg) | |
43 | 56 |
44 def heads(repo, proto): | 57 def heads(repo, proto): |
45 h = repo.heads() | 58 h = repo.heads() |
46 return " ".join(map(hex, h)) + "\n" | 59 return " ".join(map(hex, h)) + "\n" |
47 | 60 |
66 | 79 |
67 commands = { | 80 commands = { |
68 'between': (between, 'pairs'), | 81 'between': (between, 'pairs'), |
69 'branchmap': (branchmap, ''), | 82 'branchmap': (branchmap, ''), |
70 'branches': (branches, 'nodes'), | 83 'branches': (branches, 'nodes'), |
84 'changegroup': (changegroup, 'roots'), | |
85 'changegroupsubset': (changegroupsubset, 'bases heads'), | |
71 'heads': (heads, ''), | 86 'heads': (heads, ''), |
72 'listkeys': (listkeys, 'namespace'), | 87 'listkeys': (listkeys, 'namespace'), |
73 'lookup': (lookup, 'key'), | 88 'lookup': (lookup, 'key'), |
74 'pushkey': (pushkey, 'namespace key old new'), | 89 'pushkey': (pushkey, 'namespace key old new'), |
75 } | 90 } |