Mercurial > hg
comparison mercurial/match.py @ 40774:8306dac48061
match: extract a literal constant into a symbolic one
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 22 Nov 2018 17:20:32 +0100 |
parents | 2f14d1bbc9a7 |
children | 4e02f25f31c6 |
comparison
equal
deleted
inserted
replaced
40773:0605726179a0 | 40774:8306dac48061 |
---|---|
1182 if len(matchfuncs) == 1: | 1182 if len(matchfuncs) == 1: |
1183 return regex, matchfuncs[0] | 1183 return regex, matchfuncs[0] |
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 | |
1188 | |
1187 def _buildregexmatch(kindpats, globsuffix): | 1189 def _buildregexmatch(kindpats, globsuffix): |
1188 """Build a match function from a list of kinds and kindpats, | 1190 """Build a match function from a list of kinds and kindpats, |
1189 return regexp string and a matcher function.""" | 1191 return regexp string and a matcher function.""" |
1190 try: | 1192 try: |
1191 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix) | 1193 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix) |
1192 for (k, p, s) in kindpats]) | 1194 for (k, p, s) in kindpats]) |
1193 if len(regex) <= 20000: | 1195 if len(regex) <= MAX_RE_SIZE: |
1194 return regex, _rematcher(regex) | 1196 return regex, _rematcher(regex) |
1195 # We're using a Python with a tiny regex engine and we | 1197 # We're using a Python with a tiny regex engine and we |
1196 # made it explode, so we'll divide the pattern list in two | 1198 # made it explode, so we'll divide the pattern list in two |
1197 # until it works | 1199 # until it works |
1198 l = len(kindpats) | 1200 l = len(kindpats) |