--- a/mercurial/namespaces.py Sun Dec 14 12:53:50 2014 -0800
+++ b/mercurial/namespaces.py Fri Oct 17 15:28:40 2014 -0700
@@ -1,3 +1,4 @@
+from i18n import _
from mercurial import util
import weakref
@@ -58,3 +59,22 @@
self._names.insert(order, namespace, val)
else:
self._names[namespace] = val
+
+ def singlenode(self, name):
+ """
+ Return the 'best' node for the given name. Best means the first node
+ in the first nonempty list returned by a name-to-nodes mapping function
+ in the defined precedence order.
+
+ Raises a KeyError if there is no such node.
+ """
+ for ns, v in self._names.iteritems():
+ n = v['namemap'](self.repo, name)
+ if n:
+ # return max revision number
+ if len(n) > 1:
+ cl = self.repo.changelog
+ maxrev = max(cl.rev(node) for node in n)
+ return cl.node(maxrev)
+ return n[0]
+ raise KeyError(_('no such name: %s') % name)