diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -464,6 +464,16 @@ featuresetupfuncs = set() +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 + + def makelocalrepository(baseui, path, intents=None): """Create a local repository object. @@ -527,12 +537,7 @@ # 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 +550,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