[PATCH 1 of 4] store: use a subclass, not a function for fncacheopener

Matt Mackall mpm at selenic.com
Tue May 3 14:04:46 CDT 2011


On Tue, 2011-05-03 at 18:15 +0200, Adrian Buehlmann wrote:
> On 2011-05-03 17:56, Matt Mackall wrote:
> > On Mon, 2011-05-02 at 13:13 +0200, Adrian Buehlmann wrote:
> >> On 2011-05-02 10:11, Dan Villiom Podlaski Christiansen wrote:
> >>> # HG changeset patch
> >>> # User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
> >>> # Date 1304320295 -7200
> >>> # Node ID 479f03d74bf9a4509c20ed42051d059c0f11e42c
> >>> # Parent  793c12adabf12dd3a9abcfeffb4c15f62ae35b06
> >>> store: use a subclass, not a function for fncacheopener
> >>>
> >>> diff --git a/mercurial/store.py b/mercurial/store.py
> >>> --- a/mercurial/store.py
> >>> +++ b/mercurial/store.py
> >>> @@ -370,16 +370,21 @@ class fncachestore(basicstore):
> >>>          self.encode = encode
> >>>          self.path = path + '/store'
> >>>          self.createmode = _calcmode(self.path)
> >>> -        op = openertype(self.path)
> >>> +
> >>> +        storeself = self
> >>> +
> >>> +        class fncacheopener(openertype):
> >>> +            def __call__(self, path, mode='r', *args, **kw):
> >>> +                if mode not in ('r', 'rb') and path.startswith('data/'):
> >>> +                    fnc.add(path)
> >>> +                return openertype.__call__(self, storeself.encode(path), mode,
> >>> +                                           *args, **kw)
> >>> +
> >>> +        op = fncacheopener(self.path)
> >>>          op.createmode = self.createmode
> >>>          fnc = fncache(op)
> >>>          self.fncache = fnc
> >>> -
> >>> -        def fncacheopener(path, mode='r', *args, **kw):
> >>> -            if mode not in ('r', 'rb') and path.startswith('data/'):
> >>> -                fnc.add(path)
> >>> -            return op(self.encode(path), mode, *args, **kw)
> >>> -        self.opener = fncacheopener
> >>> +        self.opener = op
> >>>  
> >>>      def join(self, f):
> >>>          return self.path + '/' + self.encode(f)
> >>
> >> Funny. With this patch, the fncache object (who's job is to record the
> >> filenames seen by the fncacheopener in the 'fncache' file) uses the
> >> fncacheopener itself to open the 'fncache' file.
> > 
> > I'm presuming that's not a problem if it passes tests.
> 
> I think it creates a reference cycle, but I haven't thought particularly
> hard about it.

Ok, that could be important. Dan?

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list