Mercurial > hg
comparison mercurial/namespaces.py @ 23715:eee55c09010a
namespaces: add a namespace object
Currently, we use a dictionary object to store the namespace properties. This
is python so let's use an object. This will allow us to be more flexible in our
method signatures in the future.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Fri, 19 Dec 2014 17:00:28 -0800 |
parents | 9266d1dd6a6e |
children | f4828a8f6ae9 |
comparison
equal
deleted
inserted
replaced
23714:e3a0e7e21f54 | 23715:eee55c09010a |
---|---|
107 | 107 |
108 def names(self, repo, namespace, node): | 108 def names(self, repo, namespace, node): |
109 """method that returns a (sorted) list of names in a namespace that | 109 """method that returns a (sorted) list of names in a namespace that |
110 match a given node""" | 110 match a given node""" |
111 return sorted(self._names[namespace]['nodemap'](repo, node)) | 111 return sorted(self._names[namespace]['nodemap'](repo, node)) |
112 | |
113 class namespace(object): | |
114 """provides an interface to a namespace | |
115 | |
116 Namespaces are basically generic many-to-many mapping between some | |
117 (namespaced) names and nodes. The goal here is to control the pollution of | |
118 jamming things into tags or bookmarks (in extension-land) and to simplify | |
119 internal bits of mercurial: log output, tab completion, etc. | |
120 | |
121 More precisely, we define a mapping of names to nodes, and a mapping from | |
122 nodes to names. Each mapping returns a list. | |
123 | |
124 Furthermore, each name mapping will be passed a name to lookup which might | |
125 not be in its domain. In this case, each method should return an empty list | |
126 and not raise an error. | |
127 | |
128 This namespace object will define the properties we need: | |
129 'name': the namespace (plural form) | |
130 'templatename': name to use for templating (usually the singular form | |
131 of the plural namespace name) | |
132 'namemap': function that takes a name and returns a list of nodes | |
133 'nodemap': function that takes a node and returns a list of names | |
134 | |
135 """ | |
136 | |
137 def __init__(self, name, templatename, namemap, nodemap): | |
138 """create a namespace | |
139 | |
140 name: the namespace to be registered (in plural form) | |
141 templatename: the name to use for templating | |
142 namemap: function that inputs a node, output name(s) | |
143 nodemap: function that inputs a name, output node(s) | |
144 | |
145 """ | |
146 self.name = name | |
147 self.templatename = templatename | |
148 self.namemap = namemap | |
149 self.nodemap = nodemap |