[PATCH 1 of 3 RFC] vfs: add "vfs" fields to localrepository for migration from "opener"

Adrian Buehlmann adrian at cadifra.com
Thu Jun 28 04:10:47 CDT 2012


On 2012-06-28 10:04, Simon King wrote:
> On 28 Jun 2012, at 08:41, FUJIWARA Katsunori <foozy at lares.dti.ne.jp> wrote:
> 
>>
>> At Wed, 27 Jun 2012 15:25:01 -0500,
>> Matt Mackall wrote:
>>>
>>> On Wed, 2012-06-27 at 17:19 +0900, FUJIWARA Katsunori wrote:
>>>> At Tue, 26 Jun 2012 16:28:09 -0500,
>>>> Matt Mackall wrote:
>>>>>
>>>>> On Tue, 2012-06-26 at 12:59 +0200, Adrian Buehlmann wrote:
>>>>
>>>>>> BTW, has anyone thought about renaming __call__ on the opener class to
>>>>>> open? After all, vfs is not just an "opener" any more...
>>>>>
>>>>> Adding an alias is fine.
>>>>
>>>> Would "adding an alias" mean adding code like below ?
>>>>
>>>>    def open(self, path, mode="r", text=False, atomictemp=False):
>>>>        return self(path, mode, text, atomictemp)
>>>>
>>>> (or "self.open = self.__call__" in "__init__()")
>>>
>>> Why does it need to be in __init__?
>>
>> I just think that:
>>
>>  - defining "open()" causes indirect invocation of "__call__()" via
>>    "open()", so it requires one more "function invocation" overhead
>>    than direct "__call__()" invocation
>>
>>  - setting "self.__call__" to "self.open" seems to reduce such
>>    overhead (but it may be wrong, because I'm not so expert for
>>    Python)
>>
>> But, I don't know the other way to set "self.__call__" to "self.open"
>> than doing it in "__init__()".
>>
>> If there are any other good ways (or there is no need to mind such
>> trivial overhead), please tell me and I'll do so.
> 
> At the class level (for example, immediately after defining __call__) you can simply add "open = __call__". This causes both names in the class dictionary to point at the same function object, so there is no overhead.

The question is, do we want to change lines like

        file = repo.opener('bookmarks.current')

to

        file = repo.vfs.open('bookmarks.current')    # style A

or to

        file = repo.vfs('bookmarks.current')         # style B

?

If we rename repo.opener to repo.vfs, we have to touch such lines
anyway, so we could migrate these to using style A while we're at it.

But, of course, using style A would mean more typing.

Perhaps Matt prefers to keep the current style (B).


More information about the Mercurial-devel mailing list