Patchwork D8764: localrepo: deduplicate code around reading requires file

login
register
mail settings
Submitter phabricator
Date July 17, 2020, 2:21 p.m.
Message ID <differential-rev-PHID-DREV-4knyzgrcnbsuvik2jmqw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46793/
State New
Headers show

Comments

phabricator - July 17, 2020, 2:21 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8764

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -522,17 +522,21 @@ 
 
         raise error.RepoError(_(b'repository %s not found') % path)
 
+    def _readrequires(vfs):
+        try:
+            requirements = set(vfs.read(b'requires').splitlines())
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                raise
+            requirements = set()
+        return requirements
+
     # .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)
 
     # if .hg/requires contains the sharesafe requirement, it means
     # there exists a `.hg/store/requires` too and we should read it
@@ -545,12 +549,7 @@ 
             storevfs = vfsmod.vfs(vfsmod.vfs(sharedpath).join(b'store'))
         else:
             storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True)
-        try:
-            store_requirements = set(storevfs.read(b'requires').splitlines())
-            requirements |= store_requirements
-        except IOError as e:
-            if e.errno != errno.ENOENT:
-                raise
+        requirements |= _readrequires(storevfs)
 
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and