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

Adrian Buehlmann adrian at cadifra.com
Mon May 2 06:13:29 CDT 2011


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.

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


More information about the Mercurial-devel mailing list