Mercurial > hg-stable
diff mercurial/match.py @ 40816:3984409e144b
match: drop unnecessary wrapping of regex in group
It seems the regexes have been wrapped in an unnamed group since
b6c42714d900 (Add locate command., 2005-07-05). In that commit, the
grouping was needed because there was a "head" ('^') added before the
group and a "tail" (os.sep) added after it. It seems the head was
moved inside the group in 1c0c413cccdd (Get add and locate to use new
repo and dirstate walk code., 2005-07-18) and the tail was moved
inside the group in 89985a1b3427 (Clean up walk and changes code to
use normalised names properly., 2005-07-31), So it seems to me that
we've carried around the unnecessary group for 13 years. This patch
removes it.
Differential Revision: https://phab.mercurial-scm.org/D5352
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 02 Dec 2018 13:09:46 -0800 |
parents | e115a6452b41 |
children | 9e462fb88f79 |
line wrap: on
line diff
--- a/mercurial/match.py Sun Dec 02 13:45:20 2018 -0800 +++ b/mercurial/match.py Sun Dec 02 13:09:46 2018 -0800 @@ -1185,11 +1185,10 @@ return regex, lambda f: any(mf(f) for mf in matchfuncs) MAX_RE_SIZE = 20000 -_BASE_SIZE = len('(?:)') def _joinregexes(regexps): """gather multiple regular expressions into a single one""" - return '(?:%s)' % '|'.join(regexps) + return '|'.join(regexps) def _buildregexmatch(kindpats, globsuffix): """Build a match function from a list of kinds and kindpats, @@ -1209,17 +1208,17 @@ fullregexp = _joinregexes(regexps) startidx = 0 - groupsize = _BASE_SIZE + groupsize = 0 for idx, r in enumerate(regexps): piecesize = len(r) - if (piecesize + _BASE_SIZE) > MAX_RE_SIZE: + if piecesize > MAX_RE_SIZE: msg = _("matcher pattern is too long (%d bytes)") % piecesize raise error.Abort(msg) elif (groupsize + piecesize) > MAX_RE_SIZE: group = regexps[startidx:idx] allgroups.append(_joinregexes(group)) startidx = idx - groupsize = _BASE_SIZE + groupsize = 0 groupsize += piecesize + 1 if startidx == 0: @@ -1233,7 +1232,7 @@ except re.error: for k, p, s in kindpats: try: - _rematcher('(?:%s)' % _regex(k, p, globsuffix)) + _rematcher(_regex(k, p, globsuffix)) except re.error: if s: raise error.Abort(_("%s: invalid pattern (%s): %s") %