comparison mercurial/templatekw.py @ 33048:46fa46608ca5

namespaces: record and expose whether namespace is built-in Currently, the templating layer tends to treat each namespace as a one-off, with explicit usage of {bookmarks}, {tags}, {branch}, etc instead of using {namespaces}. It would be really useful if we could iterate over namespaces and operate on them generically. However, some consumers may wish to differentiate namespaces by whether they are built-in to core Mercurial or provided by extensions. Expected use cases include ignoring non-built-in namespaces or emitting a generic label for non-built-in namespaces. This commit introduces an attribute on namespace instances that says whether the namespace is "built-in" and then exposes this to the templating layer. As part of this, we implement a reusable extension for defining custom names on each changeset for testing. A second consumer will be introduced in a subsequent commit.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 24 Jun 2017 14:52:15 -0700
parents de8e3681c402
children 89796a25d4bb
comparison
equal deleted inserted replaced
33047:de8e3681c402 33048:46fa46608ca5
555 ctx = args['ctx'] 555 ctx = args['ctx']
556 repo = ctx.repo() 556 repo = ctx.repo()
557 557
558 namespaces = util.sortdict() 558 namespaces = util.sortdict()
559 colornames = {} 559 colornames = {}
560 builtins = {}
560 561
561 for k, ns in repo.names.iteritems(): 562 for k, ns in repo.names.iteritems():
562 namespaces[k] = showlist('name', ns.names(repo, ctx.node()), args) 563 namespaces[k] = showlist('name', ns.names(repo, ctx.node()), args)
563 colornames[k] = ns.colorname 564 colornames[k] = ns.colorname
565 builtins[k] = ns.builtin
564 566
565 f = _showlist('namespace', list(namespaces), args) 567 f = _showlist('namespace', list(namespaces), args)
566 568
567 def makemap(ns): 569 def makemap(ns):
568 return { 570 return {
569 'namespace': ns, 571 'namespace': ns,
570 'names': namespaces[ns], 572 'names': namespaces[ns],
573 'builtin': builtins[ns],
571 'colorname': colornames[ns], 574 'colorname': colornames[ns],
572 } 575 }
573 576
574 return _hybrid(f, namespaces, makemap, lambda x: x['namespace']) 577 return _hybrid(f, namespaces, makemap, lambda x: x['namespace'])
575 578