12 encoding, |
12 encoding, |
13 obsolete, |
13 obsolete, |
14 phases, |
14 phases, |
15 ) |
15 ) |
16 |
16 |
|
17 |
17 def _nslist(repo): |
18 def _nslist(repo): |
18 n = {} |
19 n = {} |
19 for k in _namespaces: |
20 for k in _namespaces: |
20 n[k] = "" |
21 n[k] = "" |
21 if not obsolete.isenabled(repo, obsolete.exchangeopt): |
22 if not obsolete.isenabled(repo, obsolete.exchangeopt): |
22 n.pop('obsolete') |
23 n.pop('obsolete') |
23 return n |
24 return n |
24 |
25 |
25 _namespaces = {"namespaces": (lambda *x: False, _nslist), |
26 |
26 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks), |
27 _namespaces = { |
27 "phases": (phases.pushphase, phases.listphases), |
28 "namespaces": (lambda *x: False, _nslist), |
28 "obsolete": (obsolete.pushmarker, obsolete.listmarkers), |
29 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks), |
29 } |
30 "phases": (phases.pushphase, phases.listphases), |
|
31 "obsolete": (obsolete.pushmarker, obsolete.listmarkers), |
|
32 } |
|
33 |
30 |
34 |
31 def register(namespace, pushkey, listkeys): |
35 def register(namespace, pushkey, listkeys): |
32 _namespaces[namespace] = (pushkey, listkeys) |
36 _namespaces[namespace] = (pushkey, listkeys) |
33 |
37 |
|
38 |
34 def _get(namespace): |
39 def _get(namespace): |
35 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {})) |
40 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {})) |
|
41 |
36 |
42 |
37 def push(repo, namespace, key, old, new): |
43 def push(repo, namespace, key, old, new): |
38 '''should succeed iff value was old''' |
44 '''should succeed iff value was old''' |
39 pk = _get(namespace)[0] |
45 pk = _get(namespace)[0] |
40 return pk(repo, key, old, new) |
46 return pk(repo, key, old, new) |
41 |
47 |
|
48 |
42 def list(repo, namespace): |
49 def list(repo, namespace): |
43 '''return a dict''' |
50 '''return a dict''' |
44 lk = _get(namespace)[1] |
51 lk = _get(namespace)[1] |
45 return lk(repo) |
52 return lk(repo) |
46 |
53 |
|
54 |
47 encode = encoding.fromlocal |
55 encode = encoding.fromlocal |
48 |
56 |
49 decode = encoding.tolocal |
57 decode = encoding.tolocal |
50 |
58 |
|
59 |
51 def encodekeys(keys): |
60 def encodekeys(keys): |
52 """encode the content of a pushkey namespace for exchange over the wire""" |
61 """encode the content of a pushkey namespace for exchange over the wire""" |
53 return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys]) |
62 return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys]) |
|
63 |
54 |
64 |
55 def decodekeys(data): |
65 def decodekeys(data): |
56 """decode the content of a pushkey namespace from exchange over the wire""" |
66 """decode the content of a pushkey namespace from exchange over the wire""" |
57 result = {} |
67 result = {} |
58 for l in data.splitlines(): |
68 for l in data.splitlines(): |