mercurial/match.py
changeset 42351 c7652f7440d9
parent 42230 7edff8dd46a7
child 42363 27d6956d386b
equal deleted inserted replaced
42350:94f3a73b6672 42351:c7652f7440d9
    21     util,
    21     util,
    22 )
    22 )
    23 from .utils import (
    23 from .utils import (
    24     stringutil,
    24     stringutil,
    25 )
    25 )
       
    26 
       
    27 try:
       
    28     from . import rustext
       
    29     rustext.__name__  # force actual import (see hgdemandimport)
       
    30 except ImportError:
       
    31     rustext = None
    26 
    32 
    27 allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
    33 allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
    28                    'rootglob',
    34                    'rootglob',
    29                    'listfile', 'listfile0', 'set', 'include', 'subinclude',
    35                    'listfile', 'listfile0', 'set', 'include', 'subinclude',
    30                    'rootfilesin')
    36                    'rootfilesin')
  1173         else:
  1179         else:
  1174             res += escape(c, c)
  1180             res += escape(c, c)
  1175     return res
  1181     return res
  1176 
  1182 
  1177 def _regex(kind, pat, globsuffix):
  1183 def _regex(kind, pat, globsuffix):
  1178     '''Convert a (normalized) pattern of any kind into a regular expression.
  1184     '''Convert a (normalized) pattern of any kind into a
       
  1185     regular expression.
  1179     globsuffix is appended to the regexp of globs.'''
  1186     globsuffix is appended to the regexp of globs.'''
       
  1187 
       
  1188     if rustext is not None:
       
  1189         try:
       
  1190             return rustext.filepatterns.build_single_regex(
       
  1191                 kind,
       
  1192                 pat,
       
  1193                 globsuffix
       
  1194             )
       
  1195         except rustext.filepatterns.PatternError:
       
  1196             raise error.ProgrammingError(
       
  1197                 'not a regex pattern: %s:%s' % (kind, pat)
       
  1198             )
       
  1199 
  1180     if not pat:
  1200     if not pat:
  1181         return ''
  1201         return ''
  1182     if kind == 're':
  1202     if kind == 're':
  1183         return pat
  1203         return pat
  1184     if kind in ('path', 'relpath'):
  1204     if kind in ('path', 'relpath'):
  1416     glob:pattern   # non-rooted glob
  1436     glob:pattern   # non-rooted glob
  1417     rootglob:pat   # rooted glob (same root as ^ in regexps)
  1437     rootglob:pat   # rooted glob (same root as ^ in regexps)
  1418     pattern        # pattern of the current default type
  1438     pattern        # pattern of the current default type
  1419 
  1439 
  1420     if sourceinfo is set, returns a list of tuples:
  1440     if sourceinfo is set, returns a list of tuples:
  1421     (pattern, lineno, originalline). This is useful to debug ignore patterns.
  1441     (pattern, lineno, originalline).
       
  1442     This is useful to debug ignore patterns.
  1422     '''
  1443     '''
       
  1444 
       
  1445     if rustext is not None:
       
  1446         result, warnings = rustext.filepatterns.read_pattern_file(
       
  1447             filepath,
       
  1448             bool(warn),
       
  1449             sourceinfo,
       
  1450         )
       
  1451 
       
  1452         for warning_params in warnings:
       
  1453             # Can't be easily emitted from Rust, because it would require
       
  1454             # a mechanism for both gettext and calling the `warn` function.
       
  1455             warn(_("%s: ignoring invalid syntax '%s'\n") % warning_params)
       
  1456 
       
  1457         return result
  1423 
  1458 
  1424     syntaxes = {
  1459     syntaxes = {
  1425         're': 'relre:',
  1460         're': 'relre:',
  1426         'regexp': 'relre:',
  1461         'regexp': 'relre:',
  1427         'glob': 'relglob:',
  1462         'glob': 'relglob:',