Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
51212:a7bba7df9189 | 51213:9f876765cbe2 |
---|---|
5 // This software may be used and distributed according to the terms of the | 5 // This software may be used and distributed according to the terms of the |
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, | |
11 exceptions::GraphError, | |
10 utils::{node_from_py_bytes, node_from_py_object}, | 12 utils::{node_from_py_bytes, node_from_py_object}, |
11 PyRevision, | 13 PyRevision, |
12 }; | 14 }; |
13 use cpython::{ | 15 use cpython::{ |
14 buffer::{Element, PyBuffer}, | 16 buffer::{Element, PyBuffer}, |
257 Ok(rust_res) | 259 Ok(rust_res) |
258 } | 260 } |
259 | 261 |
260 /// get filtered head revisions | 262 /// get filtered head revisions |
261 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { | 263 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { |
262 self.call_cindex(py, "headrevsfiltered", args, kw) | 264 let rust_res = self.inner_headrevsfiltered(py, &args.get_item(py, 0))?; |
265 let c_res = self.call_cindex(py, "headrevsfiltered", args, kw)?; | |
266 assert_eq!( | |
267 rust_res.len(), | |
268 c_res.len(py)?, | |
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) | |
263 } | 278 } |
264 | 279 |
265 /// True if the object is a snapshot | 280 /// True if the object is a snapshot |
266 def issnapshot(&self, *args, **kw) -> PyResult<bool> { | 281 def issnapshot(&self, *args, **kw) -> PyResult<bool> { |
267 let index = self.index(py).borrow(); | 282 let index = self.index(py).borrow(); |
795 .iter() | 810 .iter() |
796 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) | 811 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
797 .collect(); | 812 .collect(); |
798 Ok(PyList::new(py, &as_vec).into_object()) | 813 Ok(PyList::new(py, &as_vec).into_object()) |
799 } | 814 } |
815 | |
816 fn inner_headrevsfiltered( | |
817 &self, | |
818 py: Python, | |
819 filtered_revs: &PyObject, | |
820 ) -> PyResult<Vec<Revision>> { | |
821 let index = &mut *self.index(py).borrow_mut(); | |
822 let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; | |
823 | |
824 index | |
825 .head_revs_filtered(&filtered_revs) | |
826 .map_err(|e| GraphError::pynew(py, e)) | |
827 } | |
800 } | 828 } |
801 | 829 |
802 fn revlog_error(py: Python) -> PyErr { | 830 fn revlog_error(py: Python) -> PyErr { |
803 match py | 831 match py |
804 .import("mercurial.error") | 832 .import("mercurial.error") |