diff rust/hg-cpython/src/revlog.rs @ 51231:59183a19954e

rust-index: use interior mutability in head revs and caches For upcoming changes in `hg-cpython` switching to the `hg-core` index in ancestors iterators, we will need to avoid excessive mutability, restricting the use of mutable references on `hg::index::Index` to methods that actually logically mutate it, whereas the maintenance of caches such as `head_revs` clearly does not. We illustrate that immediately by switching to immutable borrows in the corresponding methods of `hg-cpython::MixedIndex`
author Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
date Fri, 27 Oct 2023 21:48:45 +0200
parents ca81cd96000a
children 456e0fe702e8
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs	Thu Oct 26 15:26:19 2023 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Fri Oct 27 21:48:45 2023 +0200
@@ -225,7 +225,7 @@
         self.nt(py).borrow_mut().take();
         self.docket(py).borrow_mut().take();
         self.nodemap_mmap(py).borrow_mut().take();
-        self.index(py).borrow_mut().clear_caches();
+        self.index(py).borrow().clear_caches();
         self.call_cindex(py, "clearcaches", args, kw)
     }
 
@@ -849,7 +849,7 @@
     }
 
     fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> {
-        let index = &mut *self.index(py).borrow_mut();
+        let index = &*self.index(py).borrow();
         let as_vec: Vec<PyObject> = index
             .head_revs()
             .map_err(|e| graph_error(py, e))?
@@ -881,7 +881,7 @@
         py: Python,
         py_revs: &PyTuple,
     ) -> PyResult<PyObject> {
-        let index = &mut *self.index(py).borrow_mut();
+        let index = &*self.index(py).borrow();
         let revs: Vec<_> = rev_pyiter_collect(py, py_revs.as_object(), index)?;
         let as_vec: Vec<_> = index
             .ancestors(&revs)
@@ -897,7 +897,7 @@
         py: Python,
         py_revs: &PyTuple,
     ) -> PyResult<PyObject> {
-        let index = &mut *self.index(py).borrow_mut();
+        let index = &*self.index(py).borrow();
         let revs: Vec<_> = rev_pyiter_collect(py, py_revs.as_object(), index)?;
         let as_vec: Vec<_> = index
             .common_ancestor_heads(&revs)
@@ -980,7 +980,7 @@
         target_density: f64,
         min_gap_size: usize,
     ) -> PyResult<PyObject> {
-        let index = &mut *self.index(py).borrow_mut();
+        let index = &*self.index(py).borrow();
         let revs: Vec<_> = rev_pyiter_collect(py, &revs, index)?;
         let as_nested_vec =
             index.slice_chunk_to_density(&revs, target_density, min_gap_size);