[PATCH 6 of 7] namespaces: generate template keyword when registering a namespace

Sean Farley sean.michael.farley at gmail.com
Wed Dec 17 01:20:17 CST 2014


Pierre-Yves David writes:

> On 12/16/2014 04:02 PM, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley at gmail.com>
>> # Date 1413526749 25200
>> #      Thu Oct 16 23:19:09 2014 -0700
>> # Node ID 957096b720f355369f56ceebd088a11b7ed37ebc
>> # Parent  3c155bf2bd32e0b719f6fe4dc66c635b2e87b40e
>> 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 % "BABAR: {babar}\n"}'
>>
>> diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
>> --- a/mercurial/namespaces.py
>> +++ b/mercurial/namespaces.py
>> @@ -1,7 +1,8 @@
>>   from i18n import _
>>   from mercurial import util
>> +import templatekw
>>
>>   def tolist(val):
>>       """
>>       a convenience method to return an empty list instead of None
>>       """
>> @@ -72,10 +73,18 @@ class namespaces(object):
>>           if order is not None:
>>               self._names.insert(order, namespace, val)
>>           else:
>>               self._names[namespace] = val
>>
>> +        # create template keyword for anything but branches and bookmarks,
>> +        # since those have special logic for 'current' and 'default'
>> +        if namespace not in ('bookmarks', 'branches'):
>> +            def generatekw(**args):
>> +                return templatekw.shownames(namespace, **args)
>> +
>> +            templatekw.keywords[namespace] = generatekw
>
> Instead of adding special case to avoid over-writing bookmrks and 
> branchs, we could automatically avoid adding new namespace if they 
> already exists. This would avoid issue with possible extensions and 
> running this multiple times.

Yep, that's a good idea.


More information about the Mercurial-devel mailing list