changeset 51803:45c467d8422c

localrepo: remove _readrequires function in favor of scmutil.readrequires
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 15 Aug 2024 14:56:50 +0100
parents eb952b2d224c
children e69e3d585f07
files mercurial/localrepo.py mercurial/upgrade.py
diffstat 2 files changed, 8 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Aug 15 14:53:17 2024 +0100
+++ b/mercurial/localrepo.py	Thu Aug 15 14:56:50 2024 +0100
@@ -523,20 +523,6 @@
     return sharedvfs
 
 
-def _readrequires(vfs, allowmissing):
-    """reads the require file present at root of this vfs
-    and return a set of requirements
-
-    If allowmissing is True, we suppress FileNotFoundError if raised"""
-    # requires file contains a newline-delimited list of
-    # features/capabilities the opener (us) must have in order to use
-    # the repository. This file was introduced in Mercurial 0.9.2,
-    # which means very old repositories may not have one. We assume
-    # a missing file translates to no requirements.
-    read = vfs.tryread if allowmissing else vfs.read
-    return set(read(b'requires').splitlines())
-
-
 def makelocalrepository(baseui, path: bytes, intents=None):
     """Create a local repository object.
 
@@ -598,7 +584,7 @@
 
         raise error.RepoError(_(b'repository %s not found') % path)
 
-    requirements = _readrequires(hgvfs, True)
+    requirements = scmutil.readrequires(hgvfs, True)
     shared = (
         requirementsmod.SHARED_REQUIREMENT in requirements
         or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements
@@ -626,7 +612,7 @@
         if (
             shared
             and requirementsmod.SHARESAFE_REQUIREMENT
-            not in _readrequires(sharedvfs, True)
+            not in scmutil.readrequires(sharedvfs, True)
         ):
             mismatch_warn = ui.configbool(
                 b'share', b'safe-mismatch.source-not-safe.warn'
@@ -670,9 +656,9 @@
                     hint=hint,
                 )
         else:
-            requirements |= _readrequires(storevfs, False)
+            requirements |= scmutil.readrequires(storevfs, False)
     elif shared:
-        sourcerequires = _readrequires(sharedvfs, False)
+        sourcerequires = scmutil.readrequires(sharedvfs, False)
         if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
             mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe')
             mismatch_warn = ui.configbool(
--- a/mercurial/upgrade.py	Thu Aug 15 14:53:17 2024 +0100
+++ b/mercurial/upgrade.py	Thu Aug 15 14:56:50 2024 +0100
@@ -308,7 +308,7 @@
 ):
     """Upgrades a share to use share-safe mechanism"""
     wlock = None
-    store_requirements = localrepo._readrequires(storevfs, False)
+    store_requirements = scmutil.readrequires(storevfs, False)
     original_crequirements = current_requirements.copy()
     # after upgrade, store requires will be shared, so lets find
     # the requirements which are not present in store and
@@ -325,7 +325,7 @@
         wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
         # some process might change the requirement in between, re-read
         # and update current_requirements
-        locked_requirements = localrepo._readrequires(hgvfs, True)
+        locked_requirements = scmutil.readrequires(hgvfs, True)
         if locked_requirements != original_crequirements:
             removed = current_requirements - locked_requirements
             # update current_requirements in place because it's passed
@@ -371,7 +371,7 @@
 ):
     """Downgrades a share which use share-safe to not use it"""
     wlock = None
-    source_requirements = localrepo._readrequires(sharedvfs, True)
+    source_requirements = scmutil.readrequires(sharedvfs, True)
     original_crequirements = current_requirements.copy()
     # we cannot be 100% sure on which requirements were present in store when
     # the source supported share-safe. However, we do know that working
@@ -386,7 +386,7 @@
         wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
         # some process might change the requirement in between, re-read
         # and update current_requirements
-        locked_requirements = localrepo._readrequires(hgvfs, True)
+        locked_requirements = scmutil.readrequires(hgvfs, True)
         if locked_requirements != original_crequirements:
             removed = current_requirements - locked_requirements
             # update current_requirements in place because it's passed