Mercurial > hg-stable
changeset 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 |
files | mercurial/namespaces.py tests/test-log.t |
diffstat | 2 files changed, 22 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/namespaces.py Wed Jan 14 19:39:13 2015 -0800 +++ b/mercurial/namespaces.py Wed Jan 14 19:55:20 2015 -0800 @@ -22,27 +22,27 @@ def __init__(self): self._names = util.sortdict() - # shorten the class name for less indentation - ns = namespace - # we need current mercurial named objects (bookmarks, tags, and # branches) to be initialized somewhere, so that place is here - n = ns("bookmarks", "bookmark", - lambda repo: repo._bookmarks.keys(), - lambda repo, name: tolist(repo._bookmarks.get(name)), - lambda repo, name: repo.nodebookmarks(name)) + bmknames = lambda repo: repo._bookmarks.keys() + bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name)) + bmknodemap = lambda repo, name: repo.nodebookmarks(name) + n = namespace("bookmarks", templatename="bookmark", listnames=bmknames, + namemap=bmknamemap, nodemap=bmknodemap) self.addnamespace(n) - n = ns("tags", "tag", - lambda repo: [t for t, n in repo.tagslist()], - lambda repo, name: tolist(repo._tagscache.tags.get(name)), - lambda repo, name: repo.nodetags(name)) + tagnames = lambda repo: [t for t, n in repo.tagslist()] + tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name)) + tagnodemap = lambda repo, name: repo.nodetags(name) + n = namespace("tags", templatename="tag", listnames=tagnames, + namemap=tagnamemap, nodemap=tagnodemap) self.addnamespace(n) - n = ns("branches", "branch", - lambda repo: repo.branchmap().keys(), - lambda repo, name: tolist(repo.branchtip(name, True)), - lambda repo, node: [repo[node].branch()]) + bnames = lambda repo: repo.branchmap().keys() + bnamemap = lambda repo, name: tolist(repo.branchtip(name, True)) + bnodemap = lambda repo, node: [repo[node].branch()] + n = namespace("branches", templatename="branch", listnames=bnames, + namemap=bnamemap, nodemap=bnodemap) self.addnamespace(n) def __getitem__(self, namespace):
--- a/tests/test-log.t Wed Jan 14 19:39:13 2015 -0800 +++ b/tests/test-log.t Wed Jan 14 19:55:20 2015 -0800 @@ -1567,12 +1567,13 @@ > > def reposetup(ui, repo): > foo = {'foo': repo[0].node()} - > ns = namespace("bars", "bar", - > lambda r: foo.keys(), - > lambda r, name: foo.get(name), - > lambda r, node: [name for name, n - > in foo.iteritems() - > if n == node]) + > names = lambda r: foo.keys() + > namemap = lambda r, name: foo.get(name) + > nodemap = lambda r, node: [name for name, n in foo.iteritems() + > if n == node] + > ns = namespace("bars", templatename="bar", listnames=names, + > namemap=namemap, nodemap=nodemap) + > > repo.names.addnamespace(ns) > EOF