diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -68,16 +68,12 @@ class localrepository(repo.repository): elif create: raise error.RepoError(_("repository %s already exists") % path) else: - # find requirements - requirements = set() try: - requirements = set(self.opener.read("requires").splitlines()) + requirements = scmutil.readrequires(self.opener, self.supported) except IOError, inst: if inst.errno != errno.ENOENT: raise - for r in requirements - self.supported: - raise error.RequirementError( - _("requirement '%s' not supported") % r) + requirements = set() self.sharedpath = self.path try: diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -691,3 +691,13 @@ def dirstatecopy(ui, repo, wctx, src, ds wctx.add([dst]) elif not dryrun: wctx.copy(origsrc, dst) + +def readrequires(opener, supported): + '''Reads and parses .hg/requires and checks if all entries found + are in the list of supported features.''' + requirements = set(opener.read("requires").splitlines()) + for r in requirements: + if r not in supported: + raise error.RequirementError( + _("requirement '%s' not supported") % r) + return requirements diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py +++ b/mercurial/statichttprepo.py @@ -91,12 +91,13 @@ class statichttprepository(localrepo.loc opener = build_opener(ui, authinfo) self.opener = opener(self.path) - # find requirements try: - requirements = self.opener.read("requires").splitlines() + requirements = scmutil.readrequires(self.opener, self.supported) except IOError, inst: if inst.errno != errno.ENOENT: raise + requirements = set() + # check if it is a non-empty old-style repository try: fp = self.opener("00changelog.i") @@ -108,13 +109,6 @@ class statichttprepository(localrepo.loc # we do not care about empty old-style repositories here msg = _("'%s' does not appear to be an hg repository") % path raise error.RepoError(msg) - requirements = [] - - # check them - for r in requirements: - if r not in self.supported: - raise error.RequirementError( - _("requirement '%s' not supported") % r) # setup store self.store = store.store(requirements, self.path, opener)