##// END OF EJS Templates
filelog: add a hasnode() method (API)...
Gregory Szorc -
r40423:f1a39128 default
parent child Browse files
Show More
@@ -381,6 +381,12 class sqlitefilestore(object):
381 381 def __iter__(self):
382 382 return iter(pycompat.xrange(len(self._revisions)))
383 383
384 def hasnode(self, node):
385 if node == nullid:
386 return False
387
388 return node in self._nodetorev
389
384 390 def revs(self, start=0, stop=None):
385 391 return storageutil.iterrevs(len(self._revisions), start=start,
386 392 stop=stop)
@@ -7,6 +7,10
7 7
8 8 from __future__ import absolute_import
9 9
10 from .node import (
11 nullid,
12 nullrev,
13 )
10 14 from . import (
11 15 error,
12 16 repository,
@@ -33,6 +37,16 class filelog(object):
33 37 def __iter__(self):
34 38 return self._revlog.__iter__()
35 39
40 def hasnode(self, node):
41 if node in (nullid, nullrev):
42 return False
43
44 try:
45 self._revlog.rev(node)
46 return True
47 except (TypeError, ValueError, IndexError, error.LookupError):
48 return False
49
36 50 def revs(self, start=0, stop=None):
37 51 return self._revlog.revs(start=start, stop=stop)
38 52
@@ -484,6 +484,16 class ifileindex(interfaceutil.Interface
484 484 def __iter__():
485 485 """Iterate over revision numbers for this file."""
486 486
487 def hasnode(node):
488 """Returns a bool indicating if a node is known to this store.
489
490 Implementations must only return True for full, binary node values:
491 hex nodes, revision numbers, and partial node matches must be
492 rejected.
493
494 The null node is never present.
495 """
496
487 497 def revs(start=0, stop=None):
488 498 """Iterate over revision numbers for this file, with control."""
489 499
@@ -45,6 +45,13 class ifileindextests(basetestcase):
45 45 with self.assertRaises(StopIteration):
46 46 next(gen)
47 47
48 self.assertFalse(f.hasnode(None))
49 self.assertFalse(f.hasnode(0))
50 self.assertFalse(f.hasnode(nullrev))
51 self.assertFalse(f.hasnode(nullid))
52 self.assertFalse(f.hasnode(b'0'))
53 self.assertFalse(f.hasnode(b'a' * 20))
54
48 55 # revs() should evaluate to an empty list.
49 56 self.assertEqual(list(f.revs()), [])
50 57
@@ -161,6 +168,13 class ifileindextests(basetestcase):
161 168 with self.assertRaises(StopIteration):
162 169 next(gen)
163 170
171 self.assertTrue(f.hasnode(node))
172 self.assertFalse(f.hasnode(hex(node)))
173 self.assertFalse(f.hasnode(nullrev))
174 self.assertFalse(f.hasnode(nullid))
175 self.assertFalse(f.hasnode(node[0:12]))
176 self.assertFalse(f.hasnode(hex(node)[0:20]))
177
164 178 self.assertEqual(list(f.revs()), [0])
165 179 self.assertEqual(list(f.revs(start=1)), [])
166 180 self.assertEqual(list(f.revs(start=0)), [0])
General Comments 0
You need to be logged in to leave comments. Login now