rust/hg-cpython/src/revlog.rs
changeset 51251 0409bd6ba663
parent 51250 a8ca22119385
child 51253 96e05f1a99bd
equal deleted inserted replaced
51250:a8ca22119385 51251:0409bd6ba663
   977         let index = py_rust_index_to_graph(py, index)?;
   977         let index = py_rust_index_to_graph(py, index)?;
   978         let nt = CoreNodeTree::default();  // in-RAM, fully mutable
   978         let nt = CoreNodeTree::default();  // in-RAM, fully mutable
   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)? };
   985 
  1003 
   986         let rev = UncheckedRevision(rev.0);
  1004         let rev = UncheckedRevision(rev.0);