[PATCH 2 of 6] configitems: add an official API for extensions to register config item

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jun 29 10:37:44 EDT 2017



On 06/29/2017 04:29 PM, Yuya Nishihara wrote:
> On Thu, 29 Jun 2017 23:11:57 +0900, Yuya Nishihara wrote:
>> On Thu, 29 Jun 2017 15:59:17 +0200, Pierre-Yves David wrote:
>>> On 06/29/2017 03:48 PM, Yuya Nishihara wrote:
>>>> On Tue, 27 Jun 2017 15:00:31 +0200, Pierre-Yves David wrote:
>>>>> # HG changeset patch
>>>>> # User Pierre-Yves David <pierre-yves.david at octobus.net>
>>>>> # Date 1497700100 -7200
>>>>> #      Sat Jun 17 13:48:20 2017 +0200
>>>>> # Node ID 944f8e3191e6fa37f27d52d3c94d1ef702408ae4
>>>>> # Parent  714ce79885e32305c45febf0da59b2ce2093967d
>>>>> # EXP-Topic config.register
>>>>> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
>>>>> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 944f8e3191e6
>>>>> configitems: add an official API for extensions to register config item
>>>>>
>>>>> Extensions can have a 'configtable' mapping and use
>>>>> 'registrar.configitem(table)' to retrieve the registration function.
>>>>>
>>>>> This behave in the same way as the other way for extensions to register new
>>>>> items (commands, colors, etc).
>>>>>
>>>>> diff --git a/mercurial/configitems.py b/mercurial/configitems.py
>>>>> --- a/mercurial/configitems.py
>>>>> +++ b/mercurial/configitems.py
>>>>> @@ -13,6 +13,11 @@ from . import (
>>>>>        error,
>>>>>    )
>>>>>    
>>>>> +def loadconfigtable(ui, extname, configtable):
>>>>> +    """update config item known to the ui with the extension ones"""
>>>>> +    for section, items in  configtable.items():
>>>>> +        ui._knownconfig.setdefault(section, {}).update(items)
>>>>
>>>> So this effectively updates the global configitems.coreitems, and that's
>>>> unavoidable since the passed ui is a temporary object.
>>>
>>> Hum, yes good catch, we are missing some copying around here. However
>>> you mention the ui being a temporary object can you elaborate a bit?
>>> (I've some notion of the weird life cycle of UI object but I'm not sure
>>> I follow you here.
>>
>> extensions.loadall() is called with "lui", which can be a temporary copy of
>> the main "ui". "lui" exists for preloading repo hgrc in dispatch layer.
> 
> Anyway, I think loadconfigtable() needs to update some global table. Otherwise
> newly created ui object wouldn't see the defaults defined by loaded extensions

Do we need more than ui.copy() inheriting the configtable?

Cheers,

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list