Mercurial > hg
comparison mercurial/namespaces.py @ 23610:9266d1dd6a6e
namespaces: generate template keyword when registering a namespace
For any namespace, we generate a template keyword. For example, given a
namespace 'babar', we automatically have the ability to use it in a template:
hg log -r . -T '{babars % "King: {babar}\n"}'
Furthermore, we only generate this keyword for a namespace if one doesn't
already exist. This is necessary for 'branches' and 'bookmarks' since both of
those have concepts of 'current' (something outside the namespace api) and also
allows extensions to override default behavior if desired.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Thu, 16 Oct 2014 23:19:09 -0700 |
parents | 807ee1a02bb0 |
children | eee55c09010a |
comparison
equal
deleted
inserted
replaced
23609:40fcf6c05217 | 23610:9266d1dd6a6e |
---|---|
1 from i18n import _ | 1 from i18n import _ |
2 from mercurial import util | 2 from mercurial import util |
3 import templatekw | |
3 | 4 |
4 def tolist(val): | 5 def tolist(val): |
5 """ | 6 """ |
6 a convenience method to return an empty list instead of None | 7 a convenience method to return an empty list instead of None |
7 """ | 8 """ |
72 if order is not None: | 73 if order is not None: |
73 self._names.insert(order, namespace, val) | 74 self._names.insert(order, namespace, val) |
74 else: | 75 else: |
75 self._names[namespace] = val | 76 self._names[namespace] = val |
76 | 77 |
78 # we only generate a template keyword if one does not already exist | |
79 if namespace not in templatekw.keywords: | |
80 def generatekw(**args): | |
81 return templatekw.shownames(namespace, **args) | |
82 | |
83 templatekw.keywords[namespace] = generatekw | |
84 | |
77 def singlenode(self, repo, name): | 85 def singlenode(self, repo, name): |
78 """ | 86 """ |
79 Return the 'best' node for the given name. Best means the first node | 87 Return the 'best' node for the given name. Best means the first node |
80 in the first nonempty list returned by a name-to-nodes mapping function | 88 in the first nonempty list returned by a name-to-nodes mapping function |
81 in the defined precedence order. | 89 in the defined precedence order. |