diff mercurial/scmutil.py @ 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 5f6090e559fa
children 973959fbe8ec
line wrap: on
line diff
--- 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