##// END OF EJS Templates
protocol: add proto to method prototypes
Matt Mackall -
r11583:944c2376 default
parent child Browse files
Show More
@@ -1,75 +1,75 b''
1 # wireproto.py - generic wire protocol support functions
1 # wireproto.py - generic wire protocol support functions
2 #
2 #
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
8 from i18n import _
9 from node import bin, hex
9 from node import bin, hex
10 import urllib
10 import urllib
11 import pushkey as pushkey_
11 import pushkey as pushkey_
12
12
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, *args))
18 proto.respond(func(repo, proto, *args))
19 return True
19 return True
20
20
21 def between(repo, pairs):
21 def between(repo, proto, pairs):
22 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")]
22 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")]
23 r = []
23 r = []
24 for b in repo.between(pairs):
24 for b in repo.between(pairs):
25 r.append(" ".join(map(hex, b)) + "\n")
25 r.append(" ".join(map(hex, b)) + "\n")
26 return "".join(r)
26 return "".join(r)
27
27
28 def branchmap(repo):
28 def branchmap(repo, proto):
29 branchmap = repo.branchmap()
29 branchmap = repo.branchmap()
30 heads = []
30 heads = []
31 for branch, nodes in branchmap.iteritems():
31 for branch, nodes in branchmap.iteritems():
32 branchname = urllib.quote(branch)
32 branchname = urllib.quote(branch)
33 branchnodes = [hex(node) for node in nodes]
33 branchnodes = [hex(node) for node in nodes]
34 heads.append('%s %s' % (branchname, ' '.join(branchnodes)))
34 heads.append('%s %s' % (branchname, ' '.join(branchnodes)))
35 return '\n'.join(heads)
35 return '\n'.join(heads)
36
36
37 def branches(repo, nodes):
37 def branches(repo, proto, nodes):
38 nodes = map(bin, nodes.split(" "))
38 nodes = map(bin, nodes.split(" "))
39 r = []
39 r = []
40 for b in repo.branches(nodes):
40 for b in repo.branches(nodes):
41 r.append(" ".join(map(hex, b)) + "\n")
41 r.append(" ".join(map(hex, b)) + "\n")
42 return "".join(r)
42 return "".join(r)
43
43
44 def heads(repo):
44 def heads(repo, proto):
45 h = repo.heads()
45 h = repo.heads()
46 return " ".join(map(hex, h)) + "\n"
46 return " ".join(map(hex, h)) + "\n"
47
47
48 def listkeys(repo, namespace):
48 def listkeys(repo, proto, namespace):
49 d = pushkey_.list(repo, namespace).items()
49 d = pushkey_.list(repo, namespace).items()
50 t = '\n'.join(['%s\t%s' % (k.encode('string-escape'),
50 t = '\n'.join(['%s\t%s' % (k.encode('string-escape'),
51 v.encode('string-escape')) for k, v in d])
51 v.encode('string-escape')) for k, v in d])
52 return t
52 return t
53
53
54 def lookup(repo, key):
54 def lookup(repo, proto, key):
55 try:
55 try:
56 r = hex(repo.lookup(key))
56 r = hex(repo.lookup(key))
57 success = 1
57 success = 1
58 except Exception, inst:
58 except Exception, inst:
59 r = str(inst)
59 r = str(inst)
60 success = 0
60 success = 0
61 return "%s %s\n" % (success, r)
61 return "%s %s\n" % (success, r)
62
62
63 def pushkey(repo, namespace, key, old, new):
63 def pushkey(repo, proto, namespace, key, old, new):
64 r = pushkey_.push(repo, namespace, key, old, new)
64 r = pushkey_.push(repo, namespace, key, old, new)
65 return '%s\n' % int(r)
65 return '%s\n' % int(r)
66
66
67 commands = {
67 commands = {
68 'between': (between, 'pairs'),
68 'between': (between, 'pairs'),
69 'branchmap': (branchmap, ''),
69 'branchmap': (branchmap, ''),
70 'branches': (branches, 'nodes'),
70 'branches': (branches, 'nodes'),
71 'heads': (heads, ''),
71 'heads': (heads, ''),
72 'listkeys': (listkeys, 'namespace'),
72 'listkeys': (listkeys, 'namespace'),
73 'lookup': (lookup, 'key'),
73 'lookup': (lookup, 'key'),
74 'pushkey': (pushkey, 'namespace key old new'),
74 'pushkey': (pushkey, 'namespace key old new'),
75 }
75 }
General Comments 0
You need to be logged in to leave comments. Login now