6 // GNU General Public License version 2 or any later version. |
6 // GNU General Public License version 2 or any later version. |
7 |
7 |
8 use crate::{ |
8 use crate::{ |
9 cindex, |
9 cindex, |
10 conversion::rev_pyiter_collect, |
10 conversion::rev_pyiter_collect, |
11 exceptions::GraphError, |
|
12 utils::{node_from_py_bytes, node_from_py_object}, |
11 utils::{node_from_py_bytes, node_from_py_object}, |
13 PyRevision, |
12 PyRevision, |
14 }; |
13 }; |
15 use cpython::{ |
14 use cpython::{ |
16 buffer::{Element, PyBuffer}, |
15 buffer::{Element, PyBuffer}, |
261 |
260 |
262 /// get filtered head revisions |
261 /// get filtered head revisions |
263 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { |
262 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { |
264 let rust_res = self.inner_headrevsfiltered(py, &args.get_item(py, 0))?; |
263 let rust_res = self.inner_headrevsfiltered(py, &args.get_item(py, 0))?; |
265 let c_res = self.call_cindex(py, "headrevsfiltered", args, kw)?; |
264 let c_res = self.call_cindex(py, "headrevsfiltered", args, kw)?; |
266 assert_eq!( |
265 |
267 rust_res.len(), |
266 assert_py_eq(py, "headrevsfiltered", &rust_res, &c_res)?; |
268 c_res.len(py)?, |
267 Ok(rust_res) |
269 "filtered heads differ {:?} {}", |
|
270 rust_res, |
|
271 c_res |
|
272 ); |
|
273 for (index, rev) in rust_res.iter().enumerate() { |
|
274 let c_rev: BaseRevision = c_res.get_item(py, index)?.extract(py)?; |
|
275 assert_eq!(c_rev, rev.0); |
|
276 } |
|
277 Ok(c_res) |
|
278 } |
268 } |
279 |
269 |
280 /// True if the object is a snapshot |
270 /// True if the object is a snapshot |
281 def issnapshot(&self, *args, **kw) -> PyResult<bool> { |
271 def issnapshot(&self, *args, **kw) -> PyResult<bool> { |
282 let index = self.index(py).borrow(); |
272 let index = self.index(py).borrow(); |
815 |
805 |
816 fn inner_headrevsfiltered( |
806 fn inner_headrevsfiltered( |
817 &self, |
807 &self, |
818 py: Python, |
808 py: Python, |
819 filtered_revs: &PyObject, |
809 filtered_revs: &PyObject, |
820 ) -> PyResult<Vec<Revision>> { |
810 ) -> PyResult<PyObject> { |
821 let index = &mut *self.index(py).borrow_mut(); |
811 let index = &mut *self.index(py).borrow_mut(); |
822 let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; |
812 let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; |
823 |
813 |
824 index |
814 let as_vec: Vec<PyObject> = index |
825 .head_revs_filtered(&filtered_revs) |
815 .head_revs_filtered(&filtered_revs) |
826 .map_err(|e| GraphError::pynew(py, e)) |
816 .map_err(|e| graph_error(py, e))? |
|
817 .iter() |
|
818 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
|
819 .collect(); |
|
820 Ok(PyList::new(py, &as_vec).into_object()) |
827 } |
821 } |
828 } |
822 } |
829 |
823 |
830 fn revlog_error(py: Python) -> PyErr { |
824 fn revlog_error(py: Python) -> PyErr { |
831 match py |
825 match py |