[PATCH 1 of 3 RFC] vfs: add "vfs" fields to localrepository for migration from "opener"
Matt Mackall
mpm at selenic.com
Thu Jun 28 22:23:46 UTC 2012
On Thu, 2012-06-28 at 11:10 +0200, Adrian Buehlmann wrote:
> 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
This is probably the right thing to do... eventually. Which means it
should be the coding style for new code and in check-code. Which means
any time we convert a line of code from repo.opener to repo.vfs, we
should switch to this style.
But there's no urgency. We don't have to convert everything at once.
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list