##// END OF EJS Templates
rust-revlog: add invalidation detection to `NodeTree` class...
Georges Racinet -
r52144:0409bd6b default
parent child Browse files
Show More
@@ -979,6 +979,24 b' py_class!(pub class NodeTree |py| {'
979 Self::create_instance(py, RefCell::new(nt), RefCell::new(index))
979 Self::create_instance(py, RefCell::new(nt), RefCell::new(index))
980 }
980 }
981
981
982 /// Tell whether the NodeTree is still valid
983 ///
984 /// In case of mutation of the index, the given results are not
985 /// guaranteed to be correct, and in fact, the methods borrowing
986 /// the inner index would fail because of `PySharedRef` poisoning
987 /// (generation-based guard), same as iterating on a `dict` that has
988 /// been meanwhile mutated.
989 def is_invalidated(&self) -> PyResult<bool> {
990 let leaked = self.index(py).borrow();
991 let result = unsafe { leaked.try_borrow(py) };
992 // two cases for result to be an error:
993 // - the index has previously been mutably borrowed
994 // - there is currently a mutable borrow
995 // in both cases this amounts for previous results related to
996 // the index to still be valid.
997 Ok(result.is_err())
998 }
999
982 def insert(&self, rev: PyRevision) -> PyResult<PyObject> {
1000 def insert(&self, rev: PyRevision) -> PyResult<PyObject> {
983 let leaked = self.index(py).borrow();
1001 let leaked = self.index(py).borrow();
984 let index = &*unsafe { leaked.try_borrow(py)? };
1002 let index = &*unsafe { leaked.try_borrow(py)? };
@@ -87,6 +87,10 b' class RustRevlogNodeTreeClassTest(revlog'
87 self.assertEqual(shortest, expected)
87 self.assertEqual(shortest, expected)
88 self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i)
88 self.assertEqual(nt.prefix_rev_lookup(hex_node[:shortest]), i)
89
89
90 # test invalidation (generation poisoning) detection
91 del idx[3]
92 self.assertTrue(nt.is_invalidated())
93
90
94
91 if __name__ == '__main__':
95 if __name__ == '__main__':
92 import silenttestrunner
96 import silenttestrunner
General Comments 0
You need to be logged in to leave comments. Login now