changeset 45406:034d94f8761b

requirements: introduce constants for `shared` and `relshared` requirements We add them to `WORKING_DIR_REQUIREMENTS` too as they should be stored in `.hg/requires` and have information about the type of working copy. Differential Revision: https://phab.mercurial-scm.org/D8926
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 11 Aug 2020 13:43:43 +0530
parents 05d19ca33b33
children cf21cda4281f
files mercurial/hg.py mercurial/localrepo.py mercurial/requirements.py mercurial/upgrade.py
diffstat 4 files changed, 33 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Mon Aug 10 15:47:21 2020 +0530
+++ b/mercurial/hg.py	Tue Aug 11 13:43:43 2020 +0530
@@ -354,8 +354,8 @@
             sharefile = repo.vfs.join(b'sharedpath')
             util.rename(sharefile, sharefile + b'.old')
 
-            repo.requirements.discard(b'shared')
-            repo.requirements.discard(b'relshared')
+            repo.requirements.discard(requirements.SHARED_REQUIREMENT)
+            repo.requirements.discard(requirements.RELATIVE_SHARED_REQUIREMENT)
             scmutil.writereporequirements(repo)
 
     # Removing share changes some fundamental properties of the repo instance.
--- a/mercurial/localrepo.py	Mon Aug 10 15:47:21 2020 +0530
+++ b/mercurial/localrepo.py	Tue Aug 11 13:43:43 2020 +0530
@@ -448,7 +448,7 @@
     # This is an absolute path for ``shared`` and relative to
     # ``.hg/`` for ``relshared``.
     sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n')
-    if b'relshared' in requirements:
+    if requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements:
         sharedpath = hgvfs.join(sharedpath)
 
     sharedvfs = vfsmod.vfs(sharedpath, realpath=True)
@@ -585,7 +585,10 @@
     # accessed is determined by various requirements. If `shared` or
     # `relshared` requirements are present, this indicates current repository
     # is a share and store exists in path mentioned in `.hg/sharedpath`
-    shared = b'shared' in requirements or b'relshared' in requirements
+    shared = (
+        requirementsmod.SHARED_REQUIREMENT in requirements
+        or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements
+    )
     if shared:
         sharedvfs = _getsharedvfs(hgvfs, requirements)
         storebasepath = sharedvfs.base
@@ -1047,8 +1050,8 @@
     _basesupported = supportedformats | {
         b'store',
         b'fncache',
-        b'shared',
-        b'relshared',
+        requirementsmod.SHARED_REQUIREMENT,
+        requirementsmod.RELATIVE_SHARED_REQUIREMENT,
         b'dotencode',
         requirementsmod.SPARSE_REQUIREMENT,
         requirementsmod.INTERNAL_PHASE_REQUIREMENT,
@@ -3232,9 +3235,9 @@
     if b'sharedrepo' in createopts:
         requirements = set(createopts[b'sharedrepo'].requirements)
         if createopts.get(b'sharedrelative'):
-            requirements.add(b'relshared')
+            requirements.add(requirementsmod.RELATIVE_SHARED_REQUIREMENT)
         else:
-            requirements.add(b'shared')
+            requirements.add(requirementsmod.SHARED_REQUIREMENT)
 
         return requirements
 
@@ -3343,7 +3346,10 @@
             )
             dropped.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT)
 
-        if b'shared' in requirements or b'relshared' in requirements:
+        if (
+            requirementsmod.SHARED_REQUIREMENT in requirements
+            or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements
+        ):
             raise error.Abort(
                 _(
                     b"cannot create shared repository as source was created"
--- a/mercurial/requirements.py	Mon Aug 10 15:47:21 2020 +0530
+++ b/mercurial/requirements.py	Tue Aug 11 13:43:43 2020 +0530
@@ -45,7 +45,23 @@
 # The repository use persistent nodemap for the changelog and the manifest.
 NODEMAP_REQUIREMENT = b'persistent-nodemap'
 
+# Denotes that the current repository is a share
+SHARED_REQUIREMENT = b'shared'
+
+# Denotes that current repository is a share and the shared source path is
+# relative to the current repository root path
+RELATIVE_SHARED_REQUIREMENT = b'relshared'
+
 # List of requirements which are working directory specific
 # These requirements cannot be shared between repositories if they
 # share the same store
-WORKING_DIR_REQUIREMENTS = {SPARSE_REQUIREMENT}
+# * sparse is a working directory specific functionality and hence working
+#   directory specific requirement
+# * SHARED_REQUIREMENT and RELATIVE_SHARED_REQUIREMENT are requirements which
+#   represents that the current working copy/repository shares store of another
+#   repo. Hence both of them should be stored in working copy
+WORKING_DIR_REQUIREMENTS = {
+    SPARSE_REQUIREMENT,
+    SHARED_REQUIREMENT,
+    RELATIVE_SHARED_REQUIREMENT,
+}
--- a/mercurial/upgrade.py	Mon Aug 10 15:47:21 2020 +0530
+++ b/mercurial/upgrade.py	Tue Aug 11 13:43:43 2020 +0530
@@ -64,7 +64,7 @@
         # It should (hopefully) not exist in the wild.
         b'parentdelta',
         # Upgrade should operate on the actual store, not the shared link.
-        b'shared',
+        requirements.SHARED_REQUIREMENT,
     }