From patchwork Mon Aug 18 21:18:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [06, of, 12] localrepo: add a method to return labels associated with a node From: Sean Farley X-Patchwork-Id: 5464 Message-Id: <8e603b1775c5645f0f77.1408396682@1.0.0.127.in-addr.arpa> To: mercurial-devel@selenic.com Date: Mon, 18 Aug 2014 16:18:02 -0500 # HG changeset patch # User Sean Farley # 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)