Martin Vejnár committed cb69efb

Allowable repo names can now be set as a regex in the config file.

Comments (1)

Files changed (1)


 import os, os.path
 from string import ascii_letters, digits
+import re
 class HgDirProvider(Component):
     """Provides Mercurial repositories from a directory."""
     def _new_repo(self, req):
         nohgrc = self.config.getbool('hgdir', 'nohgrc')
+        reponame_regex = self.config.get('hgdir', 'reponame_regex', r'[a-zA-Z0-9][a-zA-Z0-9_]*')
+        reponame_warning = self.config.get('hgdir', 'reponame_warning',
+            _('Repository names may only contain letters, digits and underscores.'))
         if req.method == 'POST':
             reponame = req.args.get('field_name')
             if reponame == '':
                 add_warning(req, _('The name of the new repository must be non-empty.'))
-            elif any(ch != '_' and ch not in digits and ch not in ascii_letters for ch in reponame):
-                add_warning(req, _('Repository names may only contain letters, digits and underscores.'))
-            elif reponame[0] == '_':
-                add_warning(req, _('Repository names may not begin with underscores.'))
+            elif not re.match(reponame_regex, reponame):
+                add_warning(req, reponame_warning)
             elif reponame and '/' not in reponame:
                 basepath = self.config.get('hgdir', 'base_path')
                 repodir = os.path.join(basepath, reponame)