--- a/mercurial/match.py Wed Nov 16 16:38:42 2022 +0100
+++ b/mercurial/match.py Wed Nov 16 15:39:10 2022 +0100
@@ -1323,7 +1323,7 @@
return res
-FLAG_RE = util.re.compile(b'^\(\?([aiLmsux]+)\)')
+FLAG_RE = util.re.compile(b'^\(\?([aiLmsux]+)\)(.*)')
def _regex(kind, pat, globsuffix):
@@ -1354,11 +1354,15 @@
return b'.*' + globre[len(b'[^/]*') :] + globsuffix
return b'(?:|.*/)' + globre + globsuffix
if kind == b'relre':
- if pat.startswith(b'^'):
- return pat
- if FLAG_RE.match(pat):
- return FLAG_RE.sub(br'(?\1:.*', pat) + b')'
- return b'.*' + pat
+ flag = None
+ m = FLAG_RE.match(pat)
+ if m:
+ flag, pat = m.groups()
+ if not pat.startswith(b'^'):
+ pat = b'.*' + pat
+ if flag is not None:
+ pat = br'(?%s:%s)' % (flag, pat)
+ return pat
if kind in (b'glob', b'rootglob'):
return _globre(pat) + globsuffix
raise error.ProgrammingError(b'not a regex pattern: %s:%s' % (kind, pat))