Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/namespaces.py @ 23873:9ef234021667
namespaces: use named args for namespace api
This is just a style change but makes adding new arguments more robust for
callers.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Wed, 14 Jan 2015 19:55:20 -0800 |
parents | 9f48242929a9 |
children | fef1146b8442 |
comparison
equal
deleted
inserted
replaced
23872:9f48242929a9 | 23873:9ef234021667 |
---|---|
20 _names_version = 0 | 20 _names_version = 0 |
21 | 21 |
22 def __init__(self): | 22 def __init__(self): |
23 self._names = util.sortdict() | 23 self._names = util.sortdict() |
24 | 24 |
25 # shorten the class name for less indentation | |
26 ns = namespace | |
27 | |
28 # we need current mercurial named objects (bookmarks, tags, and | 25 # we need current mercurial named objects (bookmarks, tags, and |
29 # branches) to be initialized somewhere, so that place is here | 26 # branches) to be initialized somewhere, so that place is here |
30 n = ns("bookmarks", "bookmark", | 27 bmknames = lambda repo: repo._bookmarks.keys() |
31 lambda repo: repo._bookmarks.keys(), | 28 bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name)) |
32 lambda repo, name: tolist(repo._bookmarks.get(name)), | 29 bmknodemap = lambda repo, name: repo.nodebookmarks(name) |
33 lambda repo, name: repo.nodebookmarks(name)) | 30 n = namespace("bookmarks", templatename="bookmark", listnames=bmknames, |
31 namemap=bmknamemap, nodemap=bmknodemap) | |
34 self.addnamespace(n) | 32 self.addnamespace(n) |
35 | 33 |
36 n = ns("tags", "tag", | 34 tagnames = lambda repo: [t for t, n in repo.tagslist()] |
37 lambda repo: [t for t, n in repo.tagslist()], | 35 tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) |
38 lambda repo, name: tolist(repo._tagscache.tags.get(name)), | 36 tagnodemap = lambda repo, name: repo.nodetags(name) |
39 lambda repo, name: repo.nodetags(name)) | 37 n = namespace("tags", templatename="tag", listnames=tagnames, |
38 namemap=tagnamemap, nodemap=tagnodemap) | |
40 self.addnamespace(n) | 39 self.addnamespace(n) |
41 | 40 |
42 n = ns("branches", "branch", | 41 bnames = lambda repo: repo.branchmap().keys() |
43 lambda repo: repo.branchmap().keys(), | 42 bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) |
44 lambda repo, name: tolist(repo.branchtip(name, True)), | 43 bnodemap = lambda repo, node: [repo[node].branch()] |
45 lambda repo, node: [repo[node].branch()]) | 44 n = namespace("branches", templatename="branch", listnames=bnames, |
45 namemap=bnamemap, nodemap=bnodemap) | |
46 self.addnamespace(n) | 46 self.addnamespace(n) |
47 | 47 |
48 def __getitem__(self, namespace): | 48 def __getitem__(self, namespace): |
49 """returns the namespace object""" | 49 """returns the namespace object""" |
50 return self._names[namespace] | 50 return self._names[namespace] |