Show More
@@ -15,10 +15,9 b' use cpython::{PyDict, PyModule, PyObject' | |||||
15 | use hg::dagops; |
|
15 | use hg::dagops; | |
16 | use hg::Revision; |
|
16 | use hg::Revision; | |
17 | use std::collections::HashSet; |
|
17 | use std::collections::HashSet; | |
18 |
use vcsgraph:: |
|
18 | use vcsgraph::graph::Rank; | |
19 | use vcsgraph::graph::{Parents, Rank}; |
|
|||
20 |
|
19 | |||
21 | use crate::revlog::pyindex_to_graph; |
|
20 | use crate::revlog::py_rust_index_to_graph; | |
22 |
|
21 | |||
23 | /// Using the the `index`, return heads out of any Python iterable of Revisions |
|
22 | /// Using the the `index`, return heads out of any Python iterable of Revisions | |
24 | /// |
|
23 | /// | |
@@ -28,23 +27,33 b' pub fn headrevs(' | |||||
28 | index: PyObject, |
|
27 | index: PyObject, | |
29 | revs: PyObject, |
|
28 | revs: PyObject, | |
30 | ) -> PyResult<HashSet<PyRevision>> { |
|
29 | ) -> PyResult<HashSet<PyRevision>> { | |
31 |
let |
|
30 | let py_leaked = py_rust_index_to_graph(py, index)?; | |
32 | let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs, &index)?; |
|
31 | let index = &*unsafe { py_leaked.try_borrow(py)? }; | |
33 | dagops::retain_heads(&index, &mut as_set) |
|
32 | let mut as_set: HashSet<Revision> = rev_pyiter_collect(py, &revs, index)?; | |
|
33 | dagops::retain_heads(index, &mut as_set) | |||
34 | .map_err(|e| GraphError::pynew(py, e))?; |
|
34 | .map_err(|e| GraphError::pynew(py, e))?; | |
35 | Ok(as_set.into_iter().map(Into::into).collect()) |
|
35 | Ok(as_set.into_iter().map(Into::into).collect()) | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | /// Computes the rank, i.e. the number of ancestors including itself, |
|
38 | /// Computes the rank, i.e. the number of ancestors including itself, | |
39 | /// of a node represented by its parents. |
|
39 | /// of a node represented by its parents. | |
|
40 | /// | |||
|
41 | /// Currently, the pure Rust index supports only the REVLOGV1 format, hence | |||
|
42 | /// the only possible return value is that the rank is unknown. | |||
|
43 | /// | |||
|
44 | /// References: | |||
|
45 | /// - C implementation, function `index_fast_rank()`. | |||
|
46 | /// - `impl vcsgraph::graph::RankedGraph for Index` in `crate::cindex`. | |||
40 | pub fn rank( |
|
47 | pub fn rank( | |
41 | py: Python, |
|
48 | py: Python, | |
42 | index: PyObject, |
|
49 | _index: PyObject, | |
43 | p1r: PyRevision, |
|
50 | _p1r: PyRevision, | |
44 | p2r: PyRevision, |
|
51 | _p2r: PyRevision, | |
45 | ) -> PyResult<Rank> { |
|
52 | ) -> PyResult<Rank> { | |
46 | node_rank(&pyindex_to_graph(py, index)?, &Parents([p1r.0, p2r.0])) |
|
53 | Err(GraphError::pynew_from_vcsgraph( | |
47 | .map_err(|e| GraphError::pynew_from_vcsgraph(py, e)) |
|
54 | py, | |
|
55 | vcsgraph::graph::GraphReadError::InconsistentGraphData, | |||
|
56 | )) | |||
48 | } |
|
57 | } | |
49 |
|
58 | |||
50 | /// Create the module, with `__package__` given from parent |
|
59 | /// Create the module, with `__package__` given from parent |
@@ -157,7 +157,7 b' class rustancestorstest(revlogtesting.Re' | |||||
157 | self.assertEqual(exc.args, ('InvalidRevision', wdirrev)) |
|
157 | self.assertEqual(exc.args, ('InvalidRevision', wdirrev)) | |
158 |
|
158 | |||
159 | def testheadrevs(self): |
|
159 | def testheadrevs(self): | |
160 | idx = self.parseindex() |
|
160 | idx = self.parserustindex() | |
161 | self.assertEqual(dagop.headrevs(idx, [1, 2, 3]), {3}) |
|
161 | self.assertEqual(dagop.headrevs(idx, [1, 2, 3]), {3}) | |
162 |
|
162 | |||
163 |
|
163 |
General Comments 0
You need to be logged in to leave comments.
Login now