##// END OF EJS Templates
pushkey: add an ``encode`` function...
Pierre-Yves David -
r21661:2f52a16f default
parent child Browse files
Show More
@@ -1,53 +1,54
1 # pushkey.py - dispatching for pushing and pulling keys
1 # pushkey.py - dispatching for pushing and pulling keys
2 #
2 #
3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
3 # Copyright 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 import bookmarks, phases, obsolete, encoding
8 import bookmarks, phases, obsolete, encoding
9
9
10 def _nslist(repo):
10 def _nslist(repo):
11 n = {}
11 n = {}
12 for k in _namespaces:
12 for k in _namespaces:
13 n[k] = ""
13 n[k] = ""
14 if not obsolete._enabled:
14 if not obsolete._enabled:
15 n.pop('obsolete')
15 n.pop('obsolete')
16 return n
16 return n
17
17
18 _namespaces = {"namespaces": (lambda *x: False, _nslist),
18 _namespaces = {"namespaces": (lambda *x: False, _nslist),
19 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
19 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
20 "phases": (phases.pushphase, phases.listphases),
20 "phases": (phases.pushphase, phases.listphases),
21 "obsolete": (obsolete.pushmarker, obsolete.listmarkers),
21 "obsolete": (obsolete.pushmarker, obsolete.listmarkers),
22 }
22 }
23
23
24 def register(namespace, pushkey, listkeys):
24 def register(namespace, pushkey, listkeys):
25 _namespaces[namespace] = (pushkey, listkeys)
25 _namespaces[namespace] = (pushkey, listkeys)
26
26
27 def _get(namespace):
27 def _get(namespace):
28 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))
28 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))
29
29
30 def push(repo, namespace, key, old, new):
30 def push(repo, namespace, key, old, new):
31 '''should succeed iff value was old'''
31 '''should succeed iff value was old'''
32 pk = _get(namespace)[0]
32 pk = _get(namespace)[0]
33 return pk(repo, key, old, new)
33 return pk(repo, key, old, new)
34
34
35 def list(repo, namespace):
35 def list(repo, namespace):
36 '''return a dict'''
36 '''return a dict'''
37 lk = _get(namespace)[1]
37 lk = _get(namespace)[1]
38 return lk(repo)
38 return lk(repo)
39
39
40 encode = encoding.fromlocal
41
40 decode = encoding.tolocal
42 decode = encoding.tolocal
41
43
42 def encodekeys(keys):
44 def encodekeys(keys):
43 """encode the content of a pushkey namespace for exchange over the wire"""
45 """encode the content of a pushkey namespace for exchange over the wire"""
44 enc = encoding.fromlocal
46 return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys])
45 return '\n'.join(['%s\t%s' % (enc(k), enc(v)) for k, v in keys])
46
47
47 def decodekeys(data):
48 def decodekeys(data):
48 """decode the content of a pushkey namespace from exchange over the wire"""
49 """decode the content of a pushkey namespace from exchange over the wire"""
49 result = {}
50 result = {}
50 for l in data.splitlines():
51 for l in data.splitlines():
51 k, v = l.split('\t')
52 k, v = l.split('\t')
52 result[decode(k)] = decode(v)
53 result[decode(k)] = decode(v)
53 return result
54 return result
General Comments 0
You need to be logged in to leave comments. Login now