[Request] [+- ] D8655: localrepo: unify share checking and related code
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Wed Jun 24 12:56:33 UTC 2020
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
This makes code cleaner. I might have done it in previous patch too but now the
cleanup is much easier to understand.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D8655
AFFECTED FILES
mercurial/localrepo.py
CHANGE DETAILS
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -534,17 +534,28 @@
raise
requirements = set()
+ 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 exp-sharesafe requirement, it means
# there exists a `.hg/store/requires` too and we should read it
- # TODO: make this code more stricter by checking whether store exists
- # and other checks
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)
try:
@@ -596,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:
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200624/c98e9a80/attachment-0001.html>
More information about the Mercurial-patches
mailing list