Mercurial > public > mercurial-scm > hg
diff rust/hg-cpython/src/revlog.rs @ 51213:9f876765cbe2
rust-index: add support for `headrevsfiltered`
The implementation is merged with that of `headrevs` also to make sure that
caches are up to date.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 30 Oct 2023 11:14:25 +0100 |
parents | a7bba7df9189 |
children | 898674a4dbc7 |
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs Tue Sep 19 15:21:43 2023 +0200 +++ b/rust/hg-cpython/src/revlog.rs Mon Oct 30 11:14:25 2023 +0100 @@ -7,6 +7,8 @@ use crate::{ cindex, + conversion::rev_pyiter_collect, + exceptions::GraphError, utils::{node_from_py_bytes, node_from_py_object}, PyRevision, }; @@ -259,7 +261,20 @@ /// get filtered head revisions def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { - self.call_cindex(py, "headrevsfiltered", args, kw) + let rust_res = self.inner_headrevsfiltered(py, &args.get_item(py, 0))?; + let c_res = self.call_cindex(py, "headrevsfiltered", args, kw)?; + assert_eq!( + rust_res.len(), + c_res.len(py)?, + "filtered heads differ {:?} {}", + rust_res, + c_res + ); + for (index, rev) in rust_res.iter().enumerate() { + let c_rev: BaseRevision = c_res.get_item(py, index)?.extract(py)?; + assert_eq!(c_rev, rev.0); + } + Ok(c_res) } /// True if the object is a snapshot @@ -797,6 +812,19 @@ .collect(); Ok(PyList::new(py, &as_vec).into_object()) } + + fn inner_headrevsfiltered( + &self, + py: Python, + filtered_revs: &PyObject, + ) -> PyResult<Vec<Revision>> { + let index = &mut *self.index(py).borrow_mut(); + let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; + + index + .head_revs_filtered(&filtered_revs) + .map_err(|e| GraphError::pynew(py, e)) + } } fn revlog_error(py: Python) -> PyErr {