# HG changeset patch # User Gregory Szorc # Date 2017-06-24 20:39:20 # Node ID de8e3681c402c1dab7d81eb4607e23e0df2b8148 # Parent 11f768258dcc72c71c7d4fe50b890eee54fcdc85 templatekw: expose color name in {namespaces} entries Templates make use of a "log." label. The value here differs from the actual namespace name in that the namespace itself is plural but the label/color value is singular. Expose the color name to the templating layer so log.* labels can be emitted for {namespaces}. As part of this, we refactored the logic to eliminate a gnarly comprehension. We store color names in their own dict because the lookup can occur in tight loops and we shouldn't have to go to repo.names[ns] multiple times for every changeset. diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -554,13 +554,24 @@ def shownamespaces(**args): args = pycompat.byteskwargs(args) ctx = args['ctx'] repo = ctx.repo() - namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()), - args)) - for k, ns in repo.names.iteritems()) + + namespaces = util.sortdict() + colornames = {} + + for k, ns in repo.names.iteritems(): + namespaces[k] = showlist('name', ns.names(repo, ctx.node()), args) + colornames[k] = ns.colorname + f = _showlist('namespace', list(namespaces), args) - return _hybrid(f, namespaces, - lambda k: {'namespace': k, 'names': namespaces[k]}, - lambda x: x['namespace']) + + def makemap(ns): + return { + 'namespace': ns, + 'names': namespaces[ns], + 'colorname': colornames[ns], + } + + return _hybrid(f, namespaces, makemap, lambda x: x['namespace']) @templatekeyword('node') def shownode(repo, ctx, templ, **args): diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3894,10 +3894,31 @@ Test active bookmark templating Test namespaces dict - $ hg log -T '{rev}{namespaces % " {namespace}={join(names, ",")}"}\n' - 2 bookmarks=bar,foo tags=tip branches=text.{rev} - 1 bookmarks=baz tags= branches=text.{rev} - 0 bookmarks= tags= branches=default + $ hg log -T '{rev}\n{namespaces % " {namespace} color={colorname}\n {join(names, ",")}\n"}\n' + 2 + bookmarks color=bookmark + bar,foo + tags color=tag + tip + branches color=branch + text.{rev} + + 1 + bookmarks color=bookmark + baz + tags color=tag + + branches color=branch + text.{rev} + + 0 + bookmarks color=bookmark + + tags color=tag + + branches color=branch + default + $ hg log -r2 -T '{namespaces % "{namespace}: {names}\n"}' bookmarks: bar foo tags: tip