[Request] [+- ] D8910: localrepo: refactor `.hg/requires` reading login in separate function
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Fri Aug 7 12:45:19 UTC 2020
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
In an upcoming patch, we will be reusing this to read `.hg/store/requires`, so
let's separate it in a different function before.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D8910
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
@@ -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
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200807/c0680f31/attachment.html>
More information about the Mercurial-patches
mailing list