##// END OF EJS Templates
namespaces: use namespace object instead of dictionary...
Sean Farley -
r23717:d8663e61 default
parent child Browse files
Show More
@@ -39,24 +39,27 b' class namespaces(object):'
39 39 def __init__(self):
40 40 self._names = util.sortdict()
41 41
42 addns = self.addnamespace
42 # shorten the class name for less indentation
43 ns = namespace
43 44
44 45 # we need current mercurial named objects (bookmarks, tags, and
45 46 # branches) to be initialized somewhere, so that place is here
46 addns("bookmarks", "bookmark",
47 n = ns("bookmarks", "bookmark",
47 48 lambda repo, name: tolist(repo._bookmarks.get(name)),
48 49 lambda repo, name: repo.nodebookmarks(name))
50 self.addnamespace(n)
49 51
50 addns("tags", "tag",
52 n = ns("tags", "tag",
51 53 lambda repo, name: tolist(repo._tagscache.tags.get(name)),
52 54 lambda repo, name: repo.nodetags(name))
55 self.addnamespace(n)
53 56
54 addns("branches", "branch",
57 n = ns("branches", "branch",
55 58 lambda repo, name: tolist(repo.branchtip(name)),
56 59 lambda repo, node: [repo[node].branch()])
60 self.addnamespace(n)
57 61
58 def addnamespace(self, namespace, templatename, namemap, nodemap,
59 order=None):
62 def addnamespace(self, namespace, order=None):
60 63 """
61 64 register a namespace
62 65
@@ -67,20 +70,17 b' class namespaces(object):'
67 70 order: optional argument to specify the order of namespaces
68 71 (e.g. 'branches' should be listed before 'bookmarks')
69 72 """
70 val = {'templatename': templatename,
71 'namemap': namemap,
72 'nodemap': nodemap}
73 73 if order is not None:
74 self._names.insert(order, namespace, val)
74 self._names.insert(order, namespace.name, namespace)
75 75 else:
76 self._names[namespace] = val
76 self._names[namespace.name] = namespace
77 77
78 78 # we only generate a template keyword if one does not already exist
79 if namespace not in templatekw.keywords:
79 if namespace.name not in templatekw.keywords:
80 80 def generatekw(**args):
81 return templatekw.shownames(namespace, **args)
81 return templatekw.shownames(namespace.name, **args)
82 82
83 templatekw.keywords[namespace] = generatekw
83 templatekw.keywords[namespace.name] = generatekw
84 84
85 85 def singlenode(self, repo, name):
86 86 """
@@ -91,7 +91,7 b' class namespaces(object):'
91 91 Raises a KeyError if there is no such node.
92 92 """
93 93 for ns, v in self._names.iteritems():
94 n = v['namemap'](repo, name)
94 n = v.namemap(repo, name)
95 95 if n:
96 96 # return max revision number
97 97 if len(n) > 1:
@@ -103,12 +103,12 b' class namespaces(object):'
103 103
104 104 def templatename(self, namespace):
105 105 """method that returns the template name of a namespace"""
106 return self._names[namespace]['templatename']
106 return self._names[namespace].templatename
107 107
108 108 def names(self, repo, namespace, node):
109 109 """method that returns a (sorted) list of names in a namespace that
110 110 match a given node"""
111 return sorted(self._names[namespace]['nodemap'](repo, node))
111 return sorted(self._names[namespace].nodemap(repo, node))
112 112
113 113 class namespace(object):
114 114 """provides an interface to a namespace
General Comments 0
You need to be logged in to leave comments. Login now