##// END OF EJS Templates
manifest: move matches method to be outside the interface...
Augie Fackler -
r44826:0bf3b5e8 default
parent child Browse files
Show More
@@ -985,18 +985,9 b' class imanifestdict(interfaceutil.Interf'
985 def hasdir(dir):
985 def hasdir(dir):
986 """Returns a bool indicating if a directory is in this manifest."""
986 """Returns a bool indicating if a directory is in this manifest."""
987
987
988 def matches(match):
989 """Generate a new manifest filtered through a matcher.
990
991 Returns an object conforming to the ``imanifestdict`` interface.
992 """
993
994 def walk(match):
988 def walk(match):
995 """Generator of paths in manifest satisfying a matcher.
989 """Generator of paths in manifest satisfying a matcher.
996
990
997 This is equivalent to ``self.matches(match).iterkeys()`` except a new
998 manifest object is not created.
999
1000 If the matcher has explicit files listed and they don't exist in
991 If the matcher has explicit files listed and they don't exist in
1001 the manifest, ``match.bad()`` is called for each missing file.
992 the manifest, ``match.bad()`` is called for each missing file.
1002 """
993 """
@@ -545,7 +545,7 b' class manifestdict(object):'
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()
@@ -578,8 +578,8 b' class manifestdict(object):'
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
@@ -1075,8 +1075,8 b' class treemanifest(object):'
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()
@@ -1122,9 +1122,6 b' class treemanifest(object):'
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():
@@ -1167,16 +1164,16 b' class treemanifest(object):'
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':
@@ -1207,7 +1204,7 b' class treemanifest(object):'
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
@@ -1231,8 +1228,8 b' class treemanifest(object):'
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()
@@ -171,7 +171,7 b' class basemanifesttests(object):'
171 self.assertEqual(want, m[b'foo'])
171 self.assertEqual(want, m[b'foo'])
172 # make sure the suffix survives a copy
172 # make sure the suffix survives a copy
173 match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo'])
173 match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo'])
174 m2 = m.matches(match)
174 m2 = m._matches(match)
175 self.assertEqual(want, m2[b'foo'])
175 self.assertEqual(want, m2[b'foo'])
176 self.assertEqual(1, len(m2))
176 self.assertEqual(1, len(m2))
177 m2 = m.copy()
177 m2 = m.copy()
@@ -196,7 +196,7 b' class basemanifesttests(object):'
196
196
197 match.matchfn = filt
197 match.matchfn = filt
198 with self.assertRaises(AssertionError):
198 with self.assertRaises(AssertionError):
199 m.matches(match)
199 m._matches(match)
200
200
201 def testRemoveItem(self):
201 def testRemoveItem(self):
202 m = self.parsemanifest(A_SHORT_MANIFEST)
202 m = self.parsemanifest(A_SHORT_MANIFEST)
@@ -300,7 +300,7 b' class basemanifesttests(object):'
300 m = self.parsemanifest(A_HUGE_MANIFEST)
300 m = self.parsemanifest(A_HUGE_MANIFEST)
301
301
302 match = matchmod.exact([b'file1', b'file200', b'file300'])
302 match = matchmod.exact([b'file1', b'file200', b'file300'])
303 m2 = m.matches(match)
303 m2 = m._matches(match)
304
304
305 w = (b'file1\0%sx\n' b'file200\0%sl\n' b'file300\0%s\n') % (
305 w = (b'file1\0%sx\n' b'file200\0%sl\n' b'file300\0%s\n') % (
306 HASH_2,
306 HASH_2,
@@ -318,7 +318,7 b' class basemanifesttests(object):'
318 match = matchmod.exact(
318 match = matchmod.exact(
319 [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
319 [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt', b'nonexistent']
320 )
320 )
321 m2 = m.matches(match)
321 m2 = m._matches(match)
322
322
323 self.assertEqual(
323 self.assertEqual(
324 [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
324 [b'a/b/c/bar.txt', b'a/b/d/qux.py', b'readme.txt'], m2.keys()
@@ -332,7 +332,7 b' class basemanifesttests(object):'
332 match = matchmod.match(
332 match = matchmod.match(
333 util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
333 util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath'
334 )
334 )
335 m2 = m.matches(match)
335 m2 = m._matches(match)
336
336
337 self.assertEqual([], m2.keys())
337 self.assertEqual([], m2.keys())
338
338
@@ -343,7 +343,7 b' class basemanifesttests(object):'
343
343
344 flist = m.keys()[80:300]
344 flist = m.keys()[80:300]
345 match = matchmod.exact(flist)
345 match = matchmod.exact(flist)
346 m2 = m.matches(match)
346 m2 = m._matches(match)
347
347
348 self.assertEqual(flist, m2.keys())
348 self.assertEqual(flist, m2.keys())
349
349
@@ -352,7 +352,7 b' class basemanifesttests(object):'
352 m = self.parsemanifest(A_DEEPER_MANIFEST)
352 m = self.parsemanifest(A_DEEPER_MANIFEST)
353
353
354 match = matchmod.match(util.localpath(b'/repo'), b'', [b''])
354 match = matchmod.match(util.localpath(b'/repo'), b'', [b''])
355 m2 = m.matches(match)
355 m2 = m._matches(match)
356
356
357 self.assertEqual(m.keys(), m2.keys())
357 self.assertEqual(m.keys(), m2.keys())
358
358
@@ -364,7 +364,7 b' class basemanifesttests(object):'
364 match = matchmod.match(
364 match = matchmod.match(
365 util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
365 util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath'
366 )
366 )
367 m2 = m.matches(match)
367 m2 = m._matches(match)
368
368
369 self.assertEqual(
369 self.assertEqual(
370 [
370 [
@@ -388,7 +388,7 b' class basemanifesttests(object):'
388 m = self.parsemanifest(A_DEEPER_MANIFEST)
388 m = self.parsemanifest(A_DEEPER_MANIFEST)
389
389
390 match = matchmod.exact([b'a/b'])
390 match = matchmod.exact([b'a/b'])
391 m2 = m.matches(match)
391 m2 = m._matches(match)
392
392
393 self.assertEqual([], m2.keys())
393 self.assertEqual([], m2.keys())
394
394
@@ -400,7 +400,7 b' class basemanifesttests(object):'
400 match = matchmod.match(
400 match = matchmod.match(
401 util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
401 util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath'
402 )
402 )
403 m2 = m.matches(match)
403 m2 = m._matches(match)
404
404
405 self.assertEqual(
405 self.assertEqual(
406 [
406 [
@@ -423,7 +423,7 b' class basemanifesttests(object):'
423 m = self.parsemanifest(A_DEEPER_MANIFEST)
423 m = self.parsemanifest(A_DEEPER_MANIFEST)
424
424
425 match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
425 match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt'])
426 m2 = m.matches(match)
426 m2 = m._matches(match)
427
427
428 self.assertEqual(
428 self.assertEqual(
429 [b'a/b/c/bar.txt', b'a/b/c/foo.txt', b'a/b/d/ten.txt'], m2.keys()
429 [b'a/b/c/bar.txt', b'a/b/c/foo.txt', b'a/b/d/ten.txt'], m2.keys()
General Comments 0
You need to be logged in to leave comments. Login now