narrow: extract helper for parsing narrowspec file
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 21 Sep 2018 09:19:42 -0700
changeset 40690 efd0f79246e3
parent 40689 475921a3028c
child 40691 a65fe13de84f
narrow: extract helper for parsing narrowspec file This will be used for parsing a file that's stored in a different location. Differential Revision: https://phab.mercurial-scm.org/D5277
mercurial/narrowspec.py
--- a/mercurial/narrowspec.py	Thu Nov 22 22:40:22 2018 +0900
+++ b/mercurial/narrowspec.py	Fri Sep 21 09:19:42 2018 -0700
@@ -127,6 +127,18 @@
     return matchmod.match(root, '', [], include=include or [],
                           exclude=exclude or [])
 
+def parseconfig(ui, spec):
+    # maybe we should care about the profiles returned too
+    includepats, excludepats, profiles = sparse.parseconfig(ui, spec, 'narrow')
+    if profiles:
+        raise error.Abort(_("including other spec files using '%include' is not"
+                            " supported in narrowspec"))
+
+    validatepatterns(includepats)
+    validatepatterns(excludepats)
+
+    return includepats, excludepats
+
 def load(repo):
     try:
         spec = repo.svfs.read(FILENAME)
@@ -136,17 +148,8 @@
         if e.errno == errno.ENOENT:
             return set(), set()
         raise
-    # maybe we should care about the profiles returned too
-    includepats, excludepats, profiles = sparse.parseconfig(repo.ui, spec,
-                                                            'narrow')
-    if profiles:
-        raise error.Abort(_("including other spec files using '%include' is not"
-                            " supported in narrowspec"))
 
-    validatepatterns(includepats)
-    validatepatterns(excludepats)
-
-    return includepats, excludepats
+    return parseconfig(repo.ui, spec)
 
 def save(repo, includepats, excludepats):
     validatepatterns(includepats)