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