Show More
@@ -95,21 +95,16 class namespaces(object): | |||
|
95 | 95 | |
|
96 | 96 | def singlenode(self, repo, name): |
|
97 | 97 | """ |
|
98 |
Return the 'best' node for the given name. |
|
|
99 | in the first nonempty list returned by a name-to-nodes mapping function | |
|
100 | in the defined precedence order. | |
|
98 | Return the 'best' node for the given name. What's best is defined | |
|
99 | by the namespace's singlenode() function. The first match returned by | |
|
100 | a namespace in the defined precedence order is used. | |
|
101 | 101 | |
|
102 | 102 | Raises a KeyError if there is no such node. |
|
103 | 103 | """ |
|
104 | 104 | for ns, v in self._names.iteritems(): |
|
105 |
n = v. |
|
|
105 | n = v.singlenode(repo, name) | |
|
106 | 106 | if n: |
|
107 |
|
|
|
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] | |
|
107 | return n | |
|
113 | 108 | raise KeyError(_('no such name: %s') % name) |
|
114 | 109 | |
|
115 | 110 | class namespace(object): |
@@ -142,7 +137,7 class namespace(object): | |||
|
142 | 137 | |
|
143 | 138 | def __init__(self, name, templatename=None, logname=None, colorname=None, |
|
144 | 139 | logfmt=None, listnames=None, namemap=None, nodemap=None, |
|
145 | deprecated=None, builtin=False): | |
|
140 | deprecated=None, builtin=False, singlenode=None): | |
|
146 | 141 | """create a namespace |
|
147 | 142 | |
|
148 | 143 | name: the namespace to be registered (in plural form) |
@@ -158,6 +153,7 class namespace(object): | |||
|
158 | 153 | nodemap: function that inputs a node, output name(s) |
|
159 | 154 | deprecated: set of names to be masked for ordinary use |
|
160 | 155 | builtin: whether namespace is implemented by core Mercurial |
|
156 | singlenode: function that inputs a name, output best node (or None) | |
|
161 | 157 | """ |
|
162 | 158 | self.name = name |
|
163 | 159 | self.templatename = templatename |
@@ -167,6 +163,8 class namespace(object): | |||
|
167 | 163 | self.listnames = listnames |
|
168 | 164 | self.namemap = namemap |
|
169 | 165 | self.nodemap = nodemap |
|
166 | if singlenode: | |
|
167 | self.singlenode = singlenode | |
|
170 | 168 | |
|
171 | 169 | # if logname is not specified, use the template name as backup |
|
172 | 170 | if self.logname is None: |
@@ -199,3 +197,18 class namespace(object): | |||
|
199 | 197 | |
|
200 | 198 | """ |
|
201 | 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