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

Matt Mackall mpm at selenic.com
Tue May 3 10:56:49 CDT 2011


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.

> For archive reference: This is how I tried it last time (which Matt
> rejected back then, for different reasons -- which he apparently no
> longer does):
> http://selenic.com/pipermail/mercurial-devel/2011-March/029659.html

As I said in that very thread, the whole point of using objects here is
to allow adding new methods to all openers via inheritance. You didn't
use inheritance (or I never saw it) and then promptly gave up when I
asked for it, Dan simply did what I asked. No mystery here.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list