comparison mercurial/match.py @ 49605:b3480822a251 stable

matcher: do not prepend '.*' to pattern using ^ after flags Since the previous commit (fixing wider issue), the code generated strange regex. This is now fixed and tested.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 16 Nov 2022 15:39:10 +0100
parents 3eda36e9b3d6
children c4874ebe8644
comparison
equal deleted inserted replaced
49604:086b0c4f8663 49605:b3480822a251
1321 else: 1321 else:
1322 res += escape(c, c) 1322 res += escape(c, c)
1323 return res 1323 return res
1324 1324
1325 1325
1326 FLAG_RE = util.re.compile(b'^\(\?([aiLmsux]+)\)') 1326 FLAG_RE = util.re.compile(b'^\(\?([aiLmsux]+)\)(.*)')
1327 1327
1328 1328
1329 def _regex(kind, pat, globsuffix): 1329 def _regex(kind, pat, globsuffix):
1330 """Convert a (normalized) pattern of any kind into a 1330 """Convert a (normalized) pattern of any kind into a
1331 regular expression. 1331 regular expression.
1352 # When pat has the form *XYZ (common), make the returned regex more 1352 # When pat has the form *XYZ (common), make the returned regex more
1353 # legible by returning the regex for **XYZ instead of **/*XYZ. 1353 # legible by returning the regex for **XYZ instead of **/*XYZ.
1354 return b'.*' + globre[len(b'[^/]*') :] + globsuffix 1354 return b'.*' + globre[len(b'[^/]*') :] + globsuffix
1355 return b'(?:|.*/)' + globre + globsuffix 1355 return b'(?:|.*/)' + globre + globsuffix
1356 if kind == b'relre': 1356 if kind == b'relre':
1357 if pat.startswith(b'^'): 1357 flag = None
1358 return pat 1358 m = FLAG_RE.match(pat)
1359 if FLAG_RE.match(pat): 1359 if m:
1360 return FLAG_RE.sub(br'(?\1:.*', pat) + b')' 1360 flag, pat = m.groups()
1361 return b'.*' + pat 1361 if not pat.startswith(b'^'):
1362 pat = b'.*' + pat
1363 if flag is not None:
1364 pat = br'(?%s:%s)' % (flag, pat)
1365 return pat
1362 if kind in (b'glob', b'rootglob'): 1366 if kind in (b'glob', b'rootglob'):
1363 return _globre(pat) + globsuffix 1367 return _globre(pat) + globsuffix
1364 raise error.ProgrammingError(b'not a regex pattern: %s:%s' % (kind, pat)) 1368 raise error.ProgrammingError(b'not a regex pattern: %s:%s' % (kind, pat))
1365 1369
1366 1370