[PATCH 06 of 12] localrepo: add a method to return labels associated with a node

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Aug 21 02:54:05 CDT 2014



On 08/18/2014 02:18 PM, Sean Farley wrote:
> # 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 = []

I've no idea what your mean by "nm" consider a more verbose name.


> +
> +        # 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)

"oneline on multiple line" do a simple for loop instead (and I not super 
fan of this iteration over the whole namespace.

> +        # sort by type of label, then by name
> +        nm = sorted(nm, key=lambda tup: (tup[1], tup[0]))

You could also use:

   lambda tup: tup[::-1]

but I cannot decide what it the worse


> +        return nm
>
>       def branchmap(self):
>           '''returns a dictionary {branch: [branchheads]} with branchheads
>           ordered by increasing revision number'''
>           branchmap.updatecache(self)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list