rust/hg-cpython/src/revlog.rs
changeset 51263 5b4995b40db0
parent 51262 f20c4b307a5a
child 51397 b01e7d97e167
equal deleted inserted replaced
51262:f20c4b307a5a 51263:5b4995b40db0
    95     // Holds a reference to the mmap'ed persistent nodemap data
    95     // Holds a reference to the mmap'ed persistent nodemap data
    96     data nodemap_mmap: RefCell<Option<PyBuffer>>;
    96     data nodemap_mmap: RefCell<Option<PyBuffer>>;
    97     // Holds a reference to the mmap'ed persistent index data
    97     // Holds a reference to the mmap'ed persistent index data
    98     data index_mmap: RefCell<Option<PyBuffer>>;
    98     data index_mmap: RefCell<Option<PyBuffer>>;
    99     data head_revs_py_list: RefCell<Option<PyList>>;
    99     data head_revs_py_list: RefCell<Option<PyList>>;
       
   100     data head_node_ids_py_list: RefCell<Option<PyList>>;
   100 
   101 
   101     def __new__(
   102     def __new__(
   102         _cls,
   103         _cls,
   103         data: PyObject,
   104         data: PyObject,
   104         default_header: u32,
   105         default_header: u32,
   257     def clearcaches(&self) -> PyResult<PyObject> {
   258     def clearcaches(&self) -> PyResult<PyObject> {
   258         self.nt(py).borrow_mut().take();
   259         self.nt(py).borrow_mut().take();
   259         self.docket(py).borrow_mut().take();
   260         self.docket(py).borrow_mut().take();
   260         self.nodemap_mmap(py).borrow_mut().take();
   261         self.nodemap_mmap(py).borrow_mut().take();
   261         self.head_revs_py_list(py).borrow_mut().take();
   262         self.head_revs_py_list(py).borrow_mut().take();
       
   263         self.head_node_ids_py_list(py).borrow_mut().take();
   262         self.index(py).borrow().clear_caches();
   264         self.index(py).borrow().clear_caches();
   263         Ok(py.None())
   265         Ok(py.None())
   264     }
   266     }
   265 
   267 
   266     /// return the raw binary string representing a revision
   268     /// return the raw binary string representing a revision
   628             RefCell::new(None),
   630             RefCell::new(None),
   629             RefCell::new(None),
   631             RefCell::new(None),
   630             RefCell::new(None),
   632             RefCell::new(None),
   631             RefCell::new(Some(buf)),
   633             RefCell::new(Some(buf)),
   632             RefCell::new(None),
   634             RefCell::new(None),
       
   635             RefCell::new(None),
   633         )
   636         )
   634     }
   637     }
   635 
   638 
   636     fn len(&self, py: Python) -> PyResult<usize> {
   639     fn len(&self, py: Python) -> PyResult<usize> {
   637         let rust_index_len = self.index(py).borrow().len();
   640         let rust_index_len = self.index(py).borrow().len();
   799                 )
   802                 )
   800                 .into_object()
   803                 .into_object()
   801             })
   804             })
   802             .collect();
   805             .collect();
   803 
   806 
   804         self.cache_new_heads_py_list(head_revs, py);
   807         self.cache_new_heads_py_list(&head_revs, py);
       
   808         self.cache_new_heads_node_ids_py_list(&head_revs, py);
   805 
   809 
   806         Ok(PyList::new(py, &res).into_object())
   810         Ok(PyList::new(py, &res).into_object())
   807     }
   811     }
   808 
   812 
   809     fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> {
   813     fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> {
   810         let index = &*self.index(py).borrow();
   814         let index = &*self.index(py).borrow();
   811         if let Some(new_heads) =
   815         if let Some(new_heads) =
   812             index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
   816             index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
   813         {
   817         {
   814             self.cache_new_heads_py_list(new_heads, py);
   818             self.cache_new_heads_py_list(&new_heads, py);
   815         }
   819         }
   816 
   820 
   817         Ok(self
   821         Ok(self
   818             .head_revs_py_list(py)
   822             .head_revs_py_list(py)
   819             .borrow()
   823             .borrow()
   833 
   837 
   834         if let Some(new_heads) = index
   838         if let Some(new_heads) = index
   835             .head_revs_filtered(&filtered_revs, true)
   839             .head_revs_filtered(&filtered_revs, true)
   836             .map_err(|e| graph_error(py, e))?
   840             .map_err(|e| graph_error(py, e))?
   837         {
   841         {
   838             self.cache_new_heads_py_list(new_heads, py);
   842             self.cache_new_heads_py_list(&new_heads, py);
   839         }
   843         }
   840 
   844 
   841         Ok(self
   845         Ok(self
   842             .head_revs_py_list(py)
   846             .head_revs_py_list(py)
   843             .borrow()
   847             .borrow()
   845             .expect("head revs should be cached")
   849             .expect("head revs should be cached")
   846             .clone_ref(py)
   850             .clone_ref(py)
   847             .into_object())
   851             .into_object())
   848     }
   852     }
   849 
   853 
       
   854     fn cache_new_heads_node_ids_py_list(
       
   855         &self,
       
   856         new_heads: &[Revision],
       
   857         py: Python<'_>,
       
   858     ) -> PyList {
       
   859         let index = self.index(py).borrow();
       
   860         let as_vec: Vec<PyObject> = new_heads
       
   861             .iter()
       
   862             .map(|r| {
       
   863                 PyBytes::new(
       
   864                     py,
       
   865                     index
       
   866                         .node(*r)
       
   867                         .expect("rev should have been in the index")
       
   868                         .as_bytes(),
       
   869                 )
       
   870                 .into_object()
       
   871             })
       
   872             .collect();
       
   873         let new_heads_py_list = PyList::new(py, &as_vec);
       
   874         *self.head_node_ids_py_list(py).borrow_mut() =
       
   875             Some(new_heads_py_list.clone_ref(py));
       
   876         new_heads_py_list
       
   877     }
       
   878 
   850     fn cache_new_heads_py_list(
   879     fn cache_new_heads_py_list(
   851         &self,
   880         &self,
   852         new_heads: Vec<Revision>,
   881         new_heads: &[Revision],
   853         py: Python<'_>,
   882         py: Python<'_>,
   854     ) -> PyList {
   883     ) -> PyList {
   855         let as_vec: Vec<PyObject> = new_heads
   884         let as_vec: Vec<PyObject> = new_heads
   856             .iter()
   885             .iter()
   857             .map(|r| PyRevision::from(*r).into_py_object(py).into_object())
   886             .map(|r| PyRevision::from(*r).into_py_object(py).into_object())