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