comparison mercurial/match.py @ 40776:ce401300f981

match: extract function that group regexps
author Boris Feld <boris.feld@octobus.net>
date Thu, 22 Nov 2018 17:25:49 +0100
parents 4e02f25f31c6
children 3c842749debc
comparison
equal deleted inserted replaced
40775:4e02f25f31c6 40776:ce401300f981
1184 else: 1184 else:
1185 return regex, lambda f: any(mf(f) for mf in matchfuncs) 1185 return regex, lambda f: any(mf(f) for mf in matchfuncs)
1186 1186
1187 MAX_RE_SIZE = 20000 1187 MAX_RE_SIZE = 20000
1188 1188
1189 def _joinregexes(regexps):
1190 """gather multiple regular expressions into a single one"""
1191 return '(?:%s)' % '|'.join(regexps)
1192
1189 def _buildregexmatch(kindpats, globsuffix): 1193 def _buildregexmatch(kindpats, globsuffix):
1190 """Build a match function from a list of kinds and kindpats, 1194 """Build a match function from a list of kinds and kindpats,
1191 return regexp string and a matcher function. 1195 return regexp string and a matcher function.
1192 1196
1193 Test too large input 1197 Test too large input
1197 Traceback (most recent call last): 1201 Traceback (most recent call last):
1198 ... 1202 ...
1199 OverflowError 1203 OverflowError
1200 """ 1204 """
1201 try: 1205 try:
1202 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix) 1206 regex = _joinregexes([_regex(k, p, globsuffix)
1203 for (k, p, s) in kindpats]) 1207 for (k, p, s) in kindpats])
1204 if len(regex) <= MAX_RE_SIZE: 1208 if len(regex) <= MAX_RE_SIZE:
1205 return regex, _rematcher(regex) 1209 return regex, _rematcher(regex)
1206 # We're using a Python with a tiny regex engine and we 1210 # We're using a Python with a tiny regex engine and we
1207 # made it explode, so we'll divide the pattern list in two 1211 # made it explode, so we'll divide the pattern list in two