# HG changeset patch # User smuralid # Date 2012-09-14 00:00:34 # Node ID 09d5b205529571c440a147894850b52d7541b4d7 # Parent 6047947afb6bc62b40a1e992b93e5c423a0524e7 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 @@ -341,6 +341,17 @@ class basicstore(object): 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, vfstype): vfs = vfstype(path + '/store')