comparison mercurial/manifest.py @ 44352:0bf3b5e80d30

manifest: move matches method to be outside the interface In order to adequately smoke out any legacy consumers of the method, we rename it to _matches so it's clear that it's class-private. To my amazement, all consumers of this method really only wanted matching filenames, not a full filtered manifest. Differential Revision: https://phab.mercurial-scm.org/D8085
author Augie Fackler <augie@google.com>
date Wed, 05 Feb 2020 17:13:51 -0500
parents bbecb6d80aa7
children 948fac24bc39
comparison
equal deleted inserted replaced
44351:8ec186c1ccfe 44352:0bf3b5e80d30
543 543
544 for fn in sorted(fset): 544 for fn in sorted(fset):
545 if not self.hasdir(fn): 545 if not self.hasdir(fn):
546 match.bad(fn, None) 546 match.bad(fn, None)
547 547
548 def matches(self, match): 548 def _matches(self, match):
549 '''generate a new manifest filtered by the match argument''' 549 '''generate a new manifest filtered by the match argument'''
550 if match.always(): 550 if match.always():
551 return self.copy() 551 return self.copy()
552 552
553 if self._filesfastpath(match): 553 if self._filesfastpath(match):
576 in the current/other manifest. Where the file does not exist, 576 in the current/other manifest. Where the file does not exist,
577 the nodeid will be None and the flags will be the empty 577 the nodeid will be None and the flags will be the empty
578 string. 578 string.
579 ''' 579 '''
580 if match: 580 if match:
581 m1 = self.matches(match) 581 m1 = self._matches(match)
582 m2 = m2.matches(match) 582 m2 = m2._matches(match)
583 return m1.diff(m2, clean=clean) 583 return m1.diff(m2, clean=clean)
584 return self._lm.diff(m2._lm, clean) 584 return self._lm.diff(m2._lm, clean)
585 585
586 def setflag(self, key, flag): 586 def setflag(self, key, flag):
587 self._lm[key] = self[key], flag 587 self._lm[key] = self[key], flag
1073 return copy 1073 return copy
1074 1074
1075 def filesnotin(self, m2, match=None): 1075 def filesnotin(self, m2, match=None):
1076 '''Set of files in this manifest that are not in the other''' 1076 '''Set of files in this manifest that are not in the other'''
1077 if match and not match.always(): 1077 if match and not match.always():
1078 m1 = self.matches(match) 1078 m1 = self._matches(match)
1079 m2 = m2.matches(match) 1079 m2 = m2._matches(match)
1080 return m1.filesnotin(m2) 1080 return m1.filesnotin(m2)
1081 1081
1082 files = set() 1082 files = set()
1083 1083
1084 def _filesnotin(t1, t2): 1084 def _filesnotin(t1, t2):
1120 return dirslash in self._dirs or dirslash in self._lazydirs 1120 return dirslash in self._dirs or dirslash in self._lazydirs
1121 1121
1122 def walk(self, match): 1122 def walk(self, match):
1123 '''Generates matching file names. 1123 '''Generates matching file names.
1124 1124
1125 Equivalent to manifest.matches(match).iterkeys(), but without creating
1126 an entirely new manifest.
1127
1128 It also reports nonexistent files by marking them bad with match.bad(). 1125 It also reports nonexistent files by marking them bad with match.bad().
1129 ''' 1126 '''
1130 if match.always(): 1127 if match.always():
1131 for f in iter(self): 1128 for f in iter(self):
1132 yield f 1129 yield f
1165 else: 1162 else:
1166 if not visit or p[:-1] in visit: 1163 if not visit or p[:-1] in visit:
1167 for f in self._dirs[p]._walk(match): 1164 for f in self._dirs[p]._walk(match):
1168 yield f 1165 yield f
1169 1166
1170 def matches(self, match):
1171 '''generate a new manifest filtered by the match argument'''
1172 if match.always():
1173 return self.copy()
1174
1175 return self._matches(match)
1176
1177 def _matches(self, match): 1167 def _matches(self, match):
1178 '''recursively generate a new manifest filtered by the match argument. 1168 '''recursively generate a new manifest filtered by the match argument.
1179 ''' 1169 '''
1170 if match.always():
1171 return self.copy()
1172 return self._matches_inner(match)
1173
1174 def _matches_inner(self, match):
1175 if match.always():
1176 return self.copy()
1180 1177
1181 visit = match.visitchildrenset(self._dir[:-1]) 1178 visit = match.visitchildrenset(self._dir[:-1])
1182 if visit == b'all': 1179 if visit == b'all':
1183 return self.copy() 1180 return self.copy()
1184 ret = treemanifest(self._dir) 1181 ret = treemanifest(self._dir)
1205 1202
1206 visit = self._loadchildrensetlazy(visit) 1203 visit = self._loadchildrensetlazy(visit)
1207 for dir, subm in pycompat.iteritems(self._dirs): 1204 for dir, subm in pycompat.iteritems(self._dirs):
1208 if visit and dir[:-1] not in visit: 1205 if visit and dir[:-1] not in visit:
1209 continue 1206 continue
1210 m = subm._matches(match) 1207 m = subm._matches_inner(match)
1211 if not m._isempty(): 1208 if not m._isempty():
1212 ret._dirs[dir] = m 1209 ret._dirs[dir] = m
1213 1210
1214 if not ret._isempty(): 1211 if not ret._isempty():
1215 ret._dirty = True 1212 ret._dirty = True
1229 in the current/other manifest. Where the file does not exist, 1226 in the current/other manifest. Where the file does not exist,
1230 the nodeid will be None and the flags will be the empty 1227 the nodeid will be None and the flags will be the empty
1231 string. 1228 string.
1232 ''' 1229 '''
1233 if match and not match.always(): 1230 if match and not match.always():
1234 m1 = self.matches(match) 1231 m1 = self._matches(match)
1235 m2 = m2.matches(match) 1232 m2 = m2._matches(match)
1236 return m1.diff(m2, clean=clean) 1233 return m1.diff(m2, clean=clean)
1237 result = {} 1234 result = {}
1238 emptytree = treemanifest() 1235 emptytree = treemanifest()
1239 1236
1240 def _iterativediff(t1, t2, stack): 1237 def _iterativediff(t1, t2, stack):