diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -539,15 +539,28 @@ # a missing file translates to no requirements. requirements = _readrequires(hgvfs) + shared = False + sharedpath = None + sharedvfs = None + if b'shared' in requirements or b'relshared' in requirements: + shared = True + sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') + if b'relshared' in requirements: + sharedpath = hgvfs.join(sharedpath) + + sharedvfs = vfsmod.vfs(sharedpath, realpath=True) + + if not sharedvfs.exists(): + raise error.RepoError( + _(b'.hg/sharedpath points to nonexistent directory %s') + % sharedvfs.base + ) + # if .hg/requires contains the sharesafe requirement, it means # there exists a `.hg/store/requires` too and we should read it if SHARESAFE_REQUIREMENT in requirements: - if hgvfs.exists(b'sharedpath'): - # This is a shared repo - sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') - if b'relshared' in requirements: - sharedpath = hgvfs.join(sharedpath) - storevfs = vfsmod.vfs(vfsmod.vfs(sharedpath).join(b'store')) + if shared: + storevfs = vfsmod.vfs(sharedvfs.join(b'store')) else: storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True) requirements |= _readrequires(storevfs) @@ -594,21 +607,8 @@ # ``relshared`` requirements indicate the store lives in the path contained # in the ``.hg/sharedpath`` file. This is an absolute path for # ``shared`` and relative to ``.hg/`` for ``relshared``. - if b'shared' in requirements or b'relshared' in requirements: - sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') - if b'relshared' in requirements: - sharedpath = hgvfs.join(sharedpath) - - sharedvfs = vfsmod.vfs(sharedpath, realpath=True) - - if not sharedvfs.exists(): - raise error.RepoError( - _(b'.hg/sharedpath points to nonexistent directory %s') - % sharedvfs.base - ) - + if shared: features.add(repository.REPO_FEATURE_SHARED_STORAGE) - storebasepath = sharedvfs.base cachepath = sharedvfs.join(b'cache') else: