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

Yahoo smuralid at yahoo.com
Thu Oct 11 19:09:56 CDT 2012


Yes, thats what i thought, but I didnt have access to my repo to confirm. Thanks, Adrian!

Murali

On Oct 11, 2012, at 7:05 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:

> On 2012-10-11 11:37, Adrian Buehlmann wrote:
>> 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
> 
> False alert. This looks correct. encodedstore overrides self.join, which
> does the right thing.
> 
> (sorry for the noise on this part)


More information about the Mercurial-devel mailing list