[PATCH 2 of 3] store: eliminate reference cycle in fncachestore

Simon Heimberg simohe at besonet.ch
Tue Jul 14 07:06:18 CDT 2009


Am Montag, den 13.07.2009, 22:42 +0200 schrieb Adrian Buehlmann:
> On 13.07.2009 16:15, Simon Heimberg wrote:
> > # HG changeset patch
> > # User Simon Heimberg <simohe at besonet.ch>
> > # Date 1247241244 -7200
> > # Node ID d0d02a480e6a65cac1c86f7e74445c3e71ed173a
> > # Parent  a9ab0e06c244d08c1308b843d8b3385e9051788e
> > store: eliminate reference cycle in fncachestore
> > 
> > override method instead of passing a bound method
> > pass defversion in store because it is not possible to add a property to a
> > method
> > 
> 
> I'm currently pondering:
> 
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -284,16 +284,16 @@ class fncachestore(basicstore):
>          self.pathjoiner = pathjoiner
>          self.path = self.pathjoiner(path, 'store')
>          self.createmode = _calcmode(self.path)
> -        self._op = opener(self.path)
> -        self._op.createmode = self.createmode
> -        self.fncache = fncache(self._op)
> +        op = opener(self.path)
> +        op.createmode = self.createmode
> +        self.fncache = fncache(op)
> 
>          def fncacheopener(path, mode='r', *args, **kw):
>              if (mode not in ('r', 'rb')
>                  and path.startswith('data/')
>                  and path not in self.fncache):
>                      self.fncache.add(path)
> -            return self._op(hybridencode(path), mode, *args, **kw)
> +            return op(hybridencode(path), mode, *args, **kw)
>          self.opener = fncacheopener
> 
>      def join(self, f):
> 
> 
> Would this eliminate the cycle(s)?
> 
> It looks like we don't need to keep the opener as a data attribute
> anyway.

No, it does not. There is one element less in the cycle. There are still
references to self in fncacheopener. And fncacheopener is an attribute
of self.
When self is not used, the cycle is eliminated (see patch in following
email). Then defversion can still be in localrepo.sopener, the change is
smaller. Do you prefer this?


More information about the Mercurial-devel mailing list