[Updated] [+- ] D8655: localrepo: unify share checking and related code

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sat Aug 1 14:38:22 UTC 2020


pulkit updated this revision to Diff 22173.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8655?vs=22070&id=22173

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8655/new/

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
@@ -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:



To: pulkit, #hg-reviewers, marmoute
Cc: marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200801/e73d5ce9/attachment-0001.html>


More information about the Mercurial-patches mailing list