Show More
@@ -95,21 +95,16 b' class namespaces(object):' | |||||
95 |
|
95 | |||
96 | def singlenode(self, repo, name): |
|
96 | def singlenode(self, repo, name): | |
97 | """ |
|
97 | """ | |
98 |
Return the 'best' node for the given name. |
|
98 | Return the 'best' node for the given name. What's best is defined | |
99 | in the first nonempty list returned by a name-to-nodes mapping function |
|
99 | by the namespace's singlenode() function. The first match returned by | |
100 | in the defined precedence order. |
|
100 | a namespace in the defined precedence order is used. | |
101 |
|
101 | |||
102 | Raises a KeyError if there is no such node. |
|
102 | Raises a KeyError if there is no such node. | |
103 | """ |
|
103 | """ | |
104 | for ns, v in self._names.iteritems(): |
|
104 | for ns, v in self._names.iteritems(): | |
105 |
n = v. |
|
105 | n = v.singlenode(repo, name) | |
106 | if n: |
|
106 | if n: | |
107 |
|
|
107 | return n | |
108 | if len(n) > 1: |
|
|||
109 | cl = repo.changelog |
|
|||
110 | maxrev = max(cl.rev(node) for node in n) |
|
|||
111 | return cl.node(maxrev) |
|
|||
112 | return n[0] |
|
|||
113 | raise KeyError(_('no such name: %s') % name) |
|
108 | raise KeyError(_('no such name: %s') % name) | |
114 |
|
109 | |||
115 | class namespace(object): |
|
110 | class namespace(object): | |
@@ -142,7 +137,7 b' class namespace(object):' | |||||
142 |
|
137 | |||
143 | def __init__(self, name, templatename=None, logname=None, colorname=None, |
|
138 | def __init__(self, name, templatename=None, logname=None, colorname=None, | |
144 | logfmt=None, listnames=None, namemap=None, nodemap=None, |
|
139 | logfmt=None, listnames=None, namemap=None, nodemap=None, | |
145 | deprecated=None, builtin=False): |
|
140 | deprecated=None, builtin=False, singlenode=None): | |
146 | """create a namespace |
|
141 | """create a namespace | |
147 |
|
142 | |||
148 | name: the namespace to be registered (in plural form) |
|
143 | name: the namespace to be registered (in plural form) | |
@@ -158,6 +153,7 b' class namespace(object):' | |||||
158 | nodemap: function that inputs a node, output name(s) |
|
153 | nodemap: function that inputs a node, output name(s) | |
159 | deprecated: set of names to be masked for ordinary use |
|
154 | deprecated: set of names to be masked for ordinary use | |
160 | builtin: whether namespace is implemented by core Mercurial |
|
155 | builtin: whether namespace is implemented by core Mercurial | |
|
156 | singlenode: function that inputs a name, output best node (or None) | |||
161 | """ |
|
157 | """ | |
162 | self.name = name |
|
158 | self.name = name | |
163 | self.templatename = templatename |
|
159 | self.templatename = templatename | |
@@ -167,6 +163,8 b' class namespace(object):' | |||||
167 | self.listnames = listnames |
|
163 | self.listnames = listnames | |
168 | self.namemap = namemap |
|
164 | self.namemap = namemap | |
169 | self.nodemap = nodemap |
|
165 | self.nodemap = nodemap | |
|
166 | if singlenode: | |||
|
167 | self.singlenode = singlenode | |||
170 |
|
168 | |||
171 | # if logname is not specified, use the template name as backup |
|
169 | # if logname is not specified, use the template name as backup | |
172 | if self.logname is None: |
|
170 | if self.logname is None: | |
@@ -199,3 +197,18 b' class namespace(object):' | |||||
199 |
|
197 | |||
200 | """ |
|
198 | """ | |
201 | return sorted(self.namemap(repo, name)) |
|
199 | return sorted(self.namemap(repo, name)) | |
|
200 | ||||
|
201 | def singlenode(self, repo, name): | |||
|
202 | """returns the best node for the given name | |||
|
203 | ||||
|
204 | By default, the best node is the node from nodes() with the highest | |||
|
205 | revision number. It can be overriden by the namespace.""" | |||
|
206 | n = self.namemap(repo, name) | |||
|
207 | if n: | |||
|
208 | # return max revision number | |||
|
209 | if len(n) > 1: | |||
|
210 | cl = repo.changelog | |||
|
211 | maxrev = max(cl.rev(node) for node in n) | |||
|
212 | return cl.node(maxrev) | |||
|
213 | return n[0] | |||
|
214 | return None |
General Comments 0
You need to be logged in to leave comments.
Login now