Mercurial > hg
comparison mercurial/match.py @ 40780:1e019f45fa88
match: make "groupsize" include the trailing "|"
I think this is a little easier to follow and it will simplify later
patches too.
Differential Revision: https://phab.mercurial-scm.org/D5350
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 02 Dec 2018 13:44:49 -0800 |
parents | e8c992d56465 |
children | e115a6452b41 |
comparison
equal
deleted
inserted
replaced
40779:e8c992d56465 | 40780:1e019f45fa88 |
---|---|
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 | 1187 MAX_RE_SIZE = 20000 |
1188 _BASE_SIZE = len('(?:)') - 1 | 1188 _BASE_SIZE = len('(?:)') |
1189 | 1189 |
1190 def _joinregexes(regexps): | 1190 def _joinregexes(regexps): |
1191 """gather multiple regular expressions into a single one""" | 1191 """gather multiple regular expressions into a single one""" |
1192 return '(?:%s)' % '|'.join(regexps) | 1192 return '(?:%s)' % '|'.join(regexps) |
1193 | 1193 |
1213 for idx, r in enumerate(regexps): | 1213 for idx, r in enumerate(regexps): |
1214 piecesize = len(r) | 1214 piecesize = len(r) |
1215 if (piecesize + 4) > MAX_RE_SIZE: | 1215 if (piecesize + 4) > MAX_RE_SIZE: |
1216 msg = _("matcher pattern is too long (%d bytes)") % piecesize | 1216 msg = _("matcher pattern is too long (%d bytes)") % piecesize |
1217 raise error.Abort(msg) | 1217 raise error.Abort(msg) |
1218 elif (groupsize + 1 + piecesize) > MAX_RE_SIZE: | 1218 elif (groupsize + piecesize) > MAX_RE_SIZE: |
1219 group = regexps[startidx:idx] | 1219 group = regexps[startidx:idx] |
1220 allgroups.append(_joinregexes(group)) | 1220 allgroups.append(_joinregexes(group)) |
1221 startidx = idx | 1221 startidx = idx |
1222 groupsize = _BASE_SIZE | 1222 groupsize = _BASE_SIZE |
1223 groupsize += piecesize + 1 | 1223 groupsize += piecesize + 1 |