##// END OF EJS Templates
matcher: do not prepend '.*' to pattern using ^ after flags...
marmoute -
r50500:b3480822 stable
parent child Browse files
Show More
@@ -1323,7 +1323,7 b' def _globre(pat):'
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):
@@ -1354,11 +1354,15 b' def _regex(kind, pat, globsuffix):'
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))
@@ -205,7 +205,14 b' fn _build_single_regex(entry: &IgnorePat'
205 &b"(?"[..],
205 &b"(?"[..],
206 &pattern[s + 2..e - 1],
206 &pattern[s + 2..e - 1],
207 &b":"[..],
207 &b":"[..],
208 &b".*"[..],
208 if pattern[e] == b'^'
209 || pattern[e] == b'*'
210 || pattern[e..].starts_with(b".*")
211 {
212 &b""[..]
213 } else {
214 &b".*"[..]
215 },
209 &pattern[e..],
216 &pattern[e..],
210 &b")"[..],
217 &b")"[..],
211 ]
218 ]
@@ -752,5 +759,14 b' mod tests {'
752 .unwrap(),
759 .unwrap(),
753 Some(b"(?ia:.*ba{2}r)".to_vec()),
760 Some(b"(?ia:.*ba{2}r)".to_vec()),
754 );
761 );
762 assert_eq!(
763 build_single_regex(&IgnorePattern::new(
764 PatternSyntax::RelRegexp,
765 b"(?ia)^ba{2}r",
766 Path::new("")
767 ))
768 .unwrap(),
769 Some(b"(?ia:^ba{2}r)".to_vec()),
770 );
755 }
771 }
756 }
772 }
@@ -74,6 +74,8 b' regexp with flag is the first one'
74 A dir/b.o
74 A dir/b.o
75 ? a.c
75 ? a.c
76 ? syntax
76 ? syntax
77 $ hg debugignore
78 <includematcher includes='(?i:.*\\.O$)|.*.hgignore'>
77
79
78 regex with flag is not the first one
80 regex with flag is not the first one
79
81
@@ -83,6 +85,8 b' regex with flag is not the first one'
83 A dir/b.o
85 A dir/b.o
84 ? a.c
86 ? a.c
85 ? syntax
87 ? syntax
88 $ hg debugignore
89 <includematcher includes='.*.hgignore|(?i:.*\\.O$)'>
86
90
87 flag in a pattern should affect that pattern only
91 flag in a pattern should affect that pattern only
88
92
@@ -93,6 +97,8 b' flag in a pattern should affect that pat'
93 ? .hgignore
97 ? .hgignore
94 ? a.c
98 ? a.c
95 ? syntax
99 ? syntax
100 $ hg debugignore
101 <includematcher includes='(?i:.*\\.O$)|.*.HGIGNORE'>
96
102
97 $ echo 're:.HGIGNORE' > .hgignore
103 $ echo 're:.HGIGNORE' > .hgignore
98 $ echo 're:(?i)\.O$' >> .hgignore
104 $ echo 're:(?i)\.O$' >> .hgignore
@@ -101,6 +107,32 b' flag in a pattern should affect that pat'
101 ? .hgignore
107 ? .hgignore
102 ? a.c
108 ? a.c
103 ? syntax
109 ? syntax
110 $ hg debugignore
111 <includematcher includes='.*.HGIGNORE|(?i:.*\\.O$)'>
112
113 Check that '^' after flag is properly detected.
114
115 $ echo 're:(?i)^[^a].*\.O$' > .hgignore
116 $ echo 're:.HGIGNORE' >> .hgignore
117 $ hg status
118 A dir/b.o
119 ? .hgignore
120 ? a.c
121 ? a.o
122 ? syntax
123 $ hg debugignore
124 <includematcher includes='(?i:^[^a].*\\.O$)|.*.HGIGNORE'>
125
126 $ echo 're:.HGIGNORE' > .hgignore
127 $ echo 're:(?i)^[^a].*\.O$' >> .hgignore
128 $ hg status
129 A dir/b.o
130 ? .hgignore
131 ? a.c
132 ? a.o
133 ? syntax
134 $ hg debugignore
135 <includematcher includes='.*.HGIGNORE|(?i:^[^a].*\\.O$)'>
104
136
105
137
106 further testing
138 further testing
General Comments 0
You need to be logged in to leave comments. Login now