69aeaaaf6e07: store: simplify class hierarchy

Adrian Buehlmann adrian at cadifra.com
Thu Aug 14 08:38:35 CDT 2008


> # HG changeset patch
> # User Matt Mackall <mpm at selenic.com>
> # Date 1218676723 18000
> # Node ID 69aeaaaf6e07e1eb3f1259dfa8201727af2bbb9f
> # Parent faea0d27e38fb1a61ab35982d9d46c77b58b8680
> store: simplify class hierarchy
> 
> --- a/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
> +++ b/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
> @@ -47,19 +47,24 @@
>          elif kind == stat.S_IFREG:
>              yield pe, st.st_size
>  
> -class _store:
> +def _calcmode(path):
> +    try:
> +        # files in .hg/ will be created using this mode
> +        mode = os.stat(path).st_mode
> +            # avoid some useless chmods
> +        if (0777 & ~util._umask) == (0777 & mode):
> +            mode = None
> +    except OSError:
> +        mode = None
> +    return mode
> +
> +class basicstore:
>      '''base class for local repository stores'''
> -    def __init__(self, path):
> +    def __init__(self, path, opener):
>          self.path = path
> -        try:
> -            # files in .hg/ will be created using this mode
> -            mode = os.stat(self.path).st_mode
> -            # avoid some useless chmods
> -            if (0777 & ~util._umask) == (0777 & mode):
> -                mode = None
> -        except OSError:
> -            mode = None
> -        self.createmode = mode
> +        self.createmode = _calcmode(path)
> +        self.opener = opener(self.path)
> +        self.opener.createmode = self.createmode
>  
>      def join(self, f):
>          return os.path.join(self.path, f)
> @@ -93,15 +98,10 @@
>          for x in meta:
>              yield x
>  
> -class directstore(_store):
> +class encodedstore(basicstore):
>      def __init__(self, path, opener):
> -        _store.__init__(self, path)
> -        self.opener = opener(self.path)
> -        self.opener.createmode = self.createmode
> -
> -class encodedstore(_store):
> -    def __init__(self, path, opener):
> -        _store.__init__(self, os.path.join(path, 'store'))
> +        self.path = os.path.join(path, 'store')
> +        self.createmode = _calcmode(self.path)
>          self.encodefn = encodefilename
>          op = opener(self.path)
>          op.createmode = self.createmode

For example, this creates a new attribute "createmode" on the function
http://hg.intevation.org/mercurial/crew/file/438e02b4be73/mercurial/statichttprepo.py#l28

Feels like a layering violation, since we now have again the opener
provided as a parameter.

If we have to deal again with unknown opener types, _calcmode() and setting
the createmode of (in fact, util.opener) probably should be moved back out of store.py
then.

With this, _calcmode() is for example now called on an http address for the
static-http case.

> @@ -120,7 +120,6 @@
>          return os.path.join(self.path, self.encodefn(f))
>  
>  def store(requirements, path, opener):
> -    if 'store' not in requirements:
> -        return directstore(path, opener)
> -    else:
> +    if 'store' in requirements:
>          return encodedstore(path, opener)
> +    return basicstore(path, opener)
> --- a/tests/test-verify	Wed Aug 13 20:18:43 2008 -0500
> +++ b/tests/test-verify	Wed Aug 13 20:18:43 2008 -0500
> @@ -23,4 +23,4 @@
>  echo % verify
>  hg verify
>  
> -return 0
> +exit 0
> 



More information about the Mercurial-devel mailing list