comparison rust/hg-cpython/src/revlog.rs @ 51967:69bfd6b242ed

head-revs: merge the two inner_headrevs? variants Now that there is only one method, it does not make sense to have two different "inner" method. This is especially true as we are about to add another parameter to the method. So we clean up before that.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 27 Sep 2024 00:55:54 +0200
parents e5dcaf6d4ac0
children 609700e5d8df
comparison
equal deleted inserted replaced
51966:e5dcaf6d4ac0 51967:69bfd6b242ed
308 let filtered_revs = match &args.len(py) { 308 let filtered_revs = match &args.len(py) {
309 0 => Ok(py.None()), 309 0 => Ok(py.None()),
310 1 => Ok(args.get_item(py, 0)), 310 1 => Ok(args.get_item(py, 0)),
311 _ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")), 311 _ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")),
312 }?; 312 }?;
313 let rust_res = if filtered_revs.is_none(py) { 313 self.inner_headrevs(py, &filtered_revs)
314 self.inner_headrevs(py)
315 } else {
316 self.inner_headrevsfiltered(py, &filtered_revs)
317 }?;
318 Ok(rust_res)
319 } 314 }
320 315
321 /// get head nodeids 316 /// get head nodeids
322 def head_node_ids(&self) -> PyResult<PyObject> { 317 def head_node_ids(&self) -> PyResult<PyObject> {
323 let rust_res = self.inner_head_node_ids(py)?; 318 let rust_res = self.inner_head_node_ids(py)?;
820 self.cache_new_heads_node_ids_py_list(&head_revs, py); 815 self.cache_new_heads_node_ids_py_list(&head_revs, py);
821 816
822 Ok(PyList::new(py, &res).into_object()) 817 Ok(PyList::new(py, &res).into_object())
823 } 818 }
824 819
825 fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> { 820 fn inner_headrevs(
826 let index = &*self.index(py).borrow();
827 if let Some(new_heads) =
828 index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
829 {
830 self.cache_new_heads_py_list(&new_heads, py);
831 }
832
833 Ok(self
834 .head_revs_py_list(py)
835 .borrow()
836 .as_ref()
837 .expect("head revs should be cached")
838 .clone_ref(py)
839 .into_object())
840 }
841
842 fn inner_headrevsfiltered(
843 &self, 821 &self,
844 py: Python, 822 py: Python,
845 filtered_revs: &PyObject, 823 filtered_revs: &PyObject,
846 ) -> PyResult<PyObject> { 824 ) -> PyResult<PyObject> {
847 let index = &*self.index(py).borrow(); 825 let index = &*self.index(py).borrow();
848 let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; 826
849 827 let from_core = match filtered_revs.is_none(py) {
850 if let Some(new_heads) = index 828 true => index.head_revs_shortcut(),
851 .head_revs_filtered(&filtered_revs, true) 829 false => {
852 .map_err(|e| graph_error(py, e))? 830 let filtered_revs =
853 { 831 rev_pyiter_collect(py, filtered_revs, index)?;
832 index.head_revs_filtered(&filtered_revs, true)
833 }
834 };
835
836 if let Some(new_heads) = from_core.map_err(|e| graph_error(py, e))? {
854 self.cache_new_heads_py_list(&new_heads, py); 837 self.cache_new_heads_py_list(&new_heads, py);
855 } 838 }
856 839
857 Ok(self 840 Ok(self
858 .head_revs_py_list(py) 841 .head_revs_py_list(py)