Mercurial > public > mercurial-scm > hg
comparison mercurial/match.py @ 51622:aa23b19e6da4
match: make `was_tampered_with` work recursively
This is useful if we are to use it outside of Rust, when
deciding whether or not to do some fast-path operation with
a given matcher.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Fri, 26 Apr 2024 18:53:02 +0100 |
parents | a2afa35641c9 |
children | bc94cbb49b30 |
comparison
equal
deleted
inserted
replaced
51621:e32f23f15623 | 51622:aa23b19e6da4 |
---|---|
397 def __init__(self, badfn=None): | 397 def __init__(self, badfn=None): |
398 self._was_tampered_with = False | 398 self._was_tampered_with = False |
399 if badfn is not None: | 399 if badfn is not None: |
400 self.bad = badfn | 400 self.bad = badfn |
401 | 401 |
402 def was_tampered_with(self): | 402 def was_tampered_with_nonrec(self): |
403 # [_was_tampered_with] is used to track if when extensions changed the matcher | 403 # [_was_tampered_with] is used to track if when extensions changed the matcher |
404 # behavior (crazy stuff!), so we disable the rust fast path. | 404 # behavior (crazy stuff!), so we disable the rust fast path. |
405 return self._was_tampered_with | 405 return self._was_tampered_with |
406 | |
407 def was_tampered_with(self): | |
408 return self.was_tampered_with_nonrec() | |
406 | 409 |
407 def __call__(self, fn): | 410 def __call__(self, fn): |
408 return self.matchfn(fn) | 411 return self.matchfn(fn) |
409 | 412 |
410 # Callbacks related to how the matcher is used by dirstate.walk. | 413 # Callbacks related to how the matcher is used by dirstate.walk. |
889 self._m1 = m1 | 892 self._m1 = m1 |
890 self._m2 = m2 | 893 self._m2 = m2 |
891 self.bad = m1.bad | 894 self.bad = m1.bad |
892 self.traversedir = m1.traversedir | 895 self.traversedir = m1.traversedir |
893 | 896 |
897 def was_tampered_with(self): | |
898 return ( | |
899 self.was_tampered_with_nonrec() | |
900 or self._m1.was_tampered_with() | |
901 or self._m2.was_tampered_with() | |
902 ) | |
903 | |
894 def matchfn(self, f): | 904 def matchfn(self, f): |
895 return self._m1(f) and not self._m2(f) | 905 return self._m1(f) and not self._m2(f) |
896 | 906 |
897 @propertycache | 907 @propertycache |
898 def _files(self): | 908 def _files(self): |
972 self._m1 = m1 | 982 self._m1 = m1 |
973 self._m2 = m2 | 983 self._m2 = m2 |
974 self.bad = m1.bad | 984 self.bad = m1.bad |
975 self.traversedir = m1.traversedir | 985 self.traversedir = m1.traversedir |
976 | 986 |
987 def was_tampered_with(self): | |
988 return ( | |
989 self.was_tampered_with_nonrec() | |
990 or self._m1.was_tampered_with() | |
991 or self._m2.was_tampered_with() | |
992 ) | |
993 | |
977 @propertycache | 994 @propertycache |
978 def _files(self): | 995 def _files(self): |
979 if self.isexact(): | 996 if self.isexact(): |
980 m1, m2 = self._m1, self._m2 | 997 m1, m2 = self._m1, self._m2 |
981 if not m1.isexact(): | 998 if not m1.isexact(): |
1069 # If the parent repo had a path to this subrepo and the matcher is | 1086 # If the parent repo had a path to this subrepo and the matcher is |
1070 # a prefix matcher, this submatcher always matches. | 1087 # a prefix matcher, this submatcher always matches. |
1071 if matcher.prefix(): | 1088 if matcher.prefix(): |
1072 self._always = any(f == path for f in matcher._files) | 1089 self._always = any(f == path for f in matcher._files) |
1073 | 1090 |
1091 def was_tampered_with(self): | |
1092 return ( | |
1093 self.was_tampered_with_nonrec() or self._matcher.was_tampered_with() | |
1094 ) | |
1095 | |
1074 def bad(self, f, msg): | 1096 def bad(self, f, msg): |
1075 self._matcher.bad(self._path + b"/" + f, msg) | 1097 self._matcher.bad(self._path + b"/" + f, msg) |
1076 | 1098 |
1077 def matchfn(self, f): | 1099 def matchfn(self, f): |
1078 # Some information is lost in the superclass's constructor, so we | 1100 # Some information is lost in the superclass's constructor, so we |
1202 def __init__(self, matchers): | 1224 def __init__(self, matchers): |
1203 m1 = matchers[0] | 1225 m1 = matchers[0] |
1204 super(unionmatcher, self).__init__() | 1226 super(unionmatcher, self).__init__() |
1205 self.traversedir = m1.traversedir | 1227 self.traversedir = m1.traversedir |
1206 self._matchers = matchers | 1228 self._matchers = matchers |
1229 | |
1230 def was_tampered_with(self): | |
1231 return self.was_tampered_with_nonrec() or any( | |
1232 map(lambda m: m.was_tampered_with(), self._matchers) | |
1233 ) | |
1207 | 1234 |
1208 def matchfn(self, f): | 1235 def matchfn(self, f): |
1209 for match in self._matchers: | 1236 for match in self._matchers: |
1210 if match(f): | 1237 if match(f): |
1211 return True | 1238 return True |