Show More
@@ -381,6 +381,12 class sqlitefilestore(object): | |||||
381 | def __iter__(self): |
|
381 | def __iter__(self): | |
382 | return iter(pycompat.xrange(len(self._revisions))) |
|
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 | def revs(self, start=0, stop=None): |
|
390 | def revs(self, start=0, stop=None): | |
385 | return storageutil.iterrevs(len(self._revisions), start=start, |
|
391 | return storageutil.iterrevs(len(self._revisions), start=start, | |
386 | stop=stop) |
|
392 | stop=stop) |
@@ -7,6 +7,10 | |||||
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
|
10 | from .node import ( | |||
|
11 | nullid, | |||
|
12 | nullrev, | |||
|
13 | ) | |||
10 | from . import ( |
|
14 | from . import ( | |
11 | error, |
|
15 | error, | |
12 | repository, |
|
16 | repository, | |
@@ -33,6 +37,16 class filelog(object): | |||||
33 | def __iter__(self): |
|
37 | def __iter__(self): | |
34 | return self._revlog.__iter__() |
|
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 | def revs(self, start=0, stop=None): |
|
50 | def revs(self, start=0, stop=None): | |
37 | return self._revlog.revs(start=start, stop=stop) |
|
51 | return self._revlog.revs(start=start, stop=stop) | |
38 |
|
52 |
@@ -484,6 +484,16 class ifileindex(interfaceutil.Interface | |||||
484 | def __iter__(): |
|
484 | def __iter__(): | |
485 | """Iterate over revision numbers for this file.""" |
|
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 | def revs(start=0, stop=None): |
|
497 | def revs(start=0, stop=None): | |
488 | """Iterate over revision numbers for this file, with control.""" |
|
498 | """Iterate over revision numbers for this file, with control.""" | |
489 |
|
499 |
@@ -45,6 +45,13 class ifileindextests(basetestcase): | |||||
45 | with self.assertRaises(StopIteration): |
|
45 | with self.assertRaises(StopIteration): | |
46 | next(gen) |
|
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 | # revs() should evaluate to an empty list. |
|
55 | # revs() should evaluate to an empty list. | |
49 | self.assertEqual(list(f.revs()), []) |
|
56 | self.assertEqual(list(f.revs()), []) | |
50 |
|
57 | |||
@@ -161,6 +168,13 class ifileindextests(basetestcase): | |||||
161 | with self.assertRaises(StopIteration): |
|
168 | with self.assertRaises(StopIteration): | |
162 | next(gen) |
|
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 | self.assertEqual(list(f.revs()), [0]) |
|
178 | self.assertEqual(list(f.revs()), [0]) | |
165 | self.assertEqual(list(f.revs(start=1)), []) |
|
179 | self.assertEqual(list(f.revs(start=1)), []) | |
166 | self.assertEqual(list(f.revs(start=0)), [0]) |
|
180 | self.assertEqual(list(f.revs(start=0)), [0]) |
General Comments 0
You need to be logged in to leave comments.
Login now