[PATCH 06 of 12] localrepo: add a method to return labels associated with a node
Sean Farley
sean.michael.farley at gmail.com
Mon Aug 18 16:18:02 CDT 2014
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1396309600 18000
# Mon Mar 31 18:46:40 2014 -0500
# Node ID 8e603b1775c5645f0f77abe6e0671c9ecc5eb0c6
# Parent c3f7c84a9f217365800b5d942c875ee54f33c7ae
localrepo: add a method to return labels associated with a node
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -743,10 +743,29 @@ class localrepository(object):
l = self._labels.copy()
l["tag"] = self.tags()
l["bookmark"] = self._bookmarks
return l
+ def nodelabels(self, node):
+ '''Return all labels (sorted) associated with a node.
+
+ This is a tuple of (namespace, label) instead of a dictionary
+ since the results are sorted.
+ '''
+ nm = []
+
+ # namespace name is plural
+ nm.extend((b, 'bookmarks') for b in self.nodebookmarks(node))
+ nm.extend((t, 'tags') for t in self.nodetags(node))
+
+ for labeltype, data in self._labels.iteritems():
+ nm.extend((name, labeltype) for name, n in data.iteritems()
+ if n == node)
+
+ # sort by type of label, then by name
+ nm = sorted(nm, key=lambda tup: (tup[1], tup[0]))
+ return nm
def branchmap(self):
'''returns a dictionary {branch: [branchheads]} with branchheads
ordered by increasing revision number'''
branchmap.updatecache(self)
More information about the Mercurial-devel
mailing list