Show More
@@ -1,39 +1,43 | |||||
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 |
|
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 | def encodekeys(keys): | |||
|
41 | """encode the content of a pushkey namespace for exchange over the wire""" | |||
|
42 | enc = encoding.fromlocal | |||
|
43 | return '\n'.join(['%s\t%s' % (enc(k), enc(v)) for k, v in keys]) |
General Comments 0
You need to be logged in to leave comments.
Login now