Show More
@@ -1,39 +1,43 | |||
|
1 | 1 | # pushkey.py - dispatching for pushing and pulling keys |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 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 | 10 | def _nslist(repo): |
|
11 | 11 | n = {} |
|
12 | 12 | for k in _namespaces: |
|
13 | 13 | n[k] = "" |
|
14 | 14 | if not obsolete._enabled: |
|
15 | 15 | n.pop('obsolete') |
|
16 | 16 | return n |
|
17 | 17 | |
|
18 | 18 | _namespaces = {"namespaces": (lambda *x: False, _nslist), |
|
19 | 19 | "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks), |
|
20 | 20 | "phases": (phases.pushphase, phases.listphases), |
|
21 | 21 | "obsolete": (obsolete.pushmarker, obsolete.listmarkers), |
|
22 | 22 | } |
|
23 | 23 | |
|
24 | 24 | def register(namespace, pushkey, listkeys): |
|
25 | 25 | _namespaces[namespace] = (pushkey, listkeys) |
|
26 | 26 | |
|
27 | 27 | def _get(namespace): |
|
28 | 28 | return _namespaces.get(namespace, (lambda *x: False, lambda *x: {})) |
|
29 | 29 | |
|
30 | 30 | def push(repo, namespace, key, old, new): |
|
31 | 31 | '''should succeed iff value was old''' |
|
32 | 32 | pk = _get(namespace)[0] |
|
33 | 33 | return pk(repo, key, old, new) |
|
34 | 34 | |
|
35 | 35 | def list(repo, namespace): |
|
36 | 36 | '''return a dict''' |
|
37 | 37 | lk = _get(namespace)[1] |
|
38 | 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