changeset 45354:c4fe2262435e

localrepo: refactor `.hg/requires` reading logic in separate function In an upcoming patch, we will be reusing this to read `.hg/store/requires`, so let's separate it in a different function before. Differential Revision: https://phab.mercurial-scm.org/D8910
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 07 Aug 2020 16:02:13 +0530
parents 665e911563da
children a1f51c7dce0f
files mercurial/localrepo.py
diffstat 1 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Fri Aug 07 15:52:52 2020 +0530
+++ b/mercurial/localrepo.py	Fri Aug 07 16:02:13 2020 +0530
@@ -484,6 +484,25 @@
     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 ENOENT 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.
+    try:
+        requirements = set(vfs.read(b'requires').splitlines())
+    except IOError as e:
+        if not (allowmissing and e.errno == errno.ENOENT):
+            raise
+        requirements = set()
+    return requirements
+
+
 def makelocalrepository(baseui, path, intents=None):
     """Create a local repository object.
 
@@ -546,17 +565,7 @@
 
         raise error.RepoError(_(b'repository %s not found') % path)
 
-    # .hg/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.
-    try:
-        requirements = set(hgvfs.read(b'requires').splitlines())
-    except IOError as e:
-        if e.errno != errno.ENOENT:
-            raise
-        requirements = set()
+    requirements = _readrequires(hgvfs, True)
 
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and