changeset 51971: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 dd3ccda3abc8
files rust/hg-cpython/src/revlog.rs
diffstat 1 files changed, 12 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs	Thu Sep 26 01:50:36 2024 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Fri Sep 27 00:55:54 2024 +0200
@@ -310,12 +310,7 @@
              1 => Ok(args.get_item(py, 0)),
              _ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")),
         }?;
-        let rust_res = if filtered_revs.is_none(py) {
-            self.inner_headrevs(py)
-        } else {
-            self.inner_headrevsfiltered(py, &filtered_revs)
-        }?;
-        Ok(rust_res)
+        self.inner_headrevs(py, &filtered_revs)
     }
 
     /// get head nodeids
@@ -822,35 +817,23 @@
         Ok(PyList::new(py, &res).into_object())
     }
 
-    fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> {
-        let index = &*self.index(py).borrow();
-        if let Some(new_heads) =
-            index.head_revs_shortcut().map_err(|e| graph_error(py, e))?
-        {
-            self.cache_new_heads_py_list(&new_heads, py);
-        }
-
-        Ok(self
-            .head_revs_py_list(py)
-            .borrow()
-            .as_ref()
-            .expect("head revs should be cached")
-            .clone_ref(py)
-            .into_object())
-    }
-
-    fn inner_headrevsfiltered(
+    fn inner_headrevs(
         &self,
         py: Python,
         filtered_revs: &PyObject,
     ) -> PyResult<PyObject> {
         let index = &*self.index(py).borrow();
-        let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?;
 
-        if let Some(new_heads) = index
-            .head_revs_filtered(&filtered_revs, true)
-            .map_err(|e| graph_error(py, e))?
-        {
+        let from_core = match filtered_revs.is_none(py) {
+            true => index.head_revs_shortcut(),
+            false => {
+                let filtered_revs =
+                    rev_pyiter_collect(py, filtered_revs, index)?;
+                index.head_revs_filtered(&filtered_revs, true)
+            }
+        };
+
+        if let Some(new_heads) = from_core.map_err(|e| graph_error(py, e))? {
             self.cache_new_heads_py_list(&new_heads, py);
         }