##// END OF EJS Templates
namespaces: add a method to the first matching node for a given name
Sean Farley -
r23559:3b3a962e default
parent child Browse files
Show More
@@ -1,3 +1,4 b''
1 from i18n import _
1 2 from mercurial import util
2 3 import weakref
3 4
@@ -58,3 +59,22 b' class namespaces(object):'
58 59 self._names.insert(order, namespace, val)
59 60 else:
60 61 self._names[namespace] = val
62
63 def singlenode(self, name):
64 """
65 Return the 'best' node for the given name. Best means the first node
66 in the first nonempty list returned by a name-to-nodes mapping function
67 in the defined precedence order.
68
69 Raises a KeyError if there is no such node.
70 """
71 for ns, v in self._names.iteritems():
72 n = v['namemap'](self.repo, name)
73 if n:
74 # return max revision number
75 if len(n) > 1:
76 cl = self.repo.changelog
77 maxrev = max(cl.rev(node) for node in n)
78 return cl.node(maxrev)
79 return n[0]
80 raise KeyError(_('no such name: %s') % name)
General Comments 0
You need to be logged in to leave comments. Login now