[PATCH 1 of 3] store: add a contains method to basicstore

Adrian Buehlmann adrian at cadifra.com
Thu Oct 11 04:37:54 CDT 2012


On 2012-09-14 09:01, S Muralidhar wrote:
> # HG changeset patch
> # User smuralid
> # Date 1347580834 25200
> # Node ID 293063ca7f0332f26e5278b341628d83f2ef37f8
> # Parent  fc1a5d0eb3bbb1116051b65dcd2873389f9d7ed4
> store: add a contains method to basicstore
> 
> Adds a __contains__ method to basicstore that checks if a file/dir is present in the store
> 
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -286,6 +286,17 @@
>      def write(self):
>          pass
>  
> +    def __contains__(self, path):
> +        '''Checks if the store contains path'''
> +        path = "/".join(("data", path))
> +        # file?
> +        if os.path.exists(self.join(path + ".i")):
> +            return True
> +        # dir?
> +        if not path.endswith("/"):
> +            path = path + "/"
> +        return os.path.exists(self.join(path))
> +
>  class encodedstore(basicstore):
>      def __init__(self, path, openertype):
>          self.path = path + '/store'

I think this doesn't work correctly for encodedstore objects
(corresponds to repositories with no "fncache" entry in .hg/requires [1]).

IIUC encodedstore inherits __contains__ from basicstore, but this looks
unsuitable to me, as encodedstore has its file names encoded and
__contains__ of basicstore queries the filesystem with unencoded path names.

Adding testcases for all kinds of stores might be a good idea (albeit a
painful exercise, but it would prevent or uncover such errors).

[1] http://mercurial.selenic.com/wiki/RequiresFile


More information about the Mercurial-devel mailing list