changeset 14482:58b36e9ea783

introduce new function scmutil.readrequires for reading and parsing the .hg/requires file
author Adrian Buehlmann <adrian@cadifra.com>
date Tue, 31 May 2011 19:16:18 +0200
parents b2ee161328e0
children 973959fbe8ec
files mercurial/localrepo.py mercurial/scmutil.py mercurial/statichttprepo.py
diffstat 3 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Tue May 31 15:28:23 2011 -0500
+++ b/mercurial/localrepo.py	Tue May 31 19:16:18 2011 +0200
@@ -68,16 +68,12 @@
         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:
--- a/mercurial/scmutil.py	Tue May 31 15:28:23 2011 -0500
+++ b/mercurial/scmutil.py	Tue May 31 19:16:18 2011 +0200
@@ -691,3 +691,13 @@
                 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
--- a/mercurial/statichttprepo.py	Tue May 31 15:28:23 2011 -0500
+++ b/mercurial/statichttprepo.py	Tue May 31 19:16:18 2011 +0200
@@ -91,12 +91,13 @@
         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 @@
                 # 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)