Show More
@@ -23,6 +23,10 b' pub struct PartialDiscovery<G: Graph + C' | |||
|
23 | 23 | missing: HashSet<Revision>, |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | pub struct DiscoveryStats { | |
|
27 | pub undecided: Option<usize>, | |
|
28 | } | |
|
29 | ||
|
26 | 30 | impl<G: Graph + Clone> PartialDiscovery<G> { |
|
27 | 31 | /// Create a PartialDiscovery object, with the intent |
|
28 | 32 | /// of comparing our `::<target_heads>` revset to the contents of another |
@@ -119,6 +123,13 b' impl<G: Graph + Clone> PartialDiscovery<' | |||
|
119 | 123 | Some(self.common.missing_ancestors(tgt)?.into_iter().collect()); |
|
120 | 124 | Ok(()) |
|
121 | 125 | } |
|
126 | ||
|
127 | /// Provide statistics about the current state of the discovery process | |
|
128 | pub fn stats(&self) -> DiscoveryStats { | |
|
129 | DiscoveryStats { | |
|
130 | undecided: self.undecided.as_ref().map(|s| s.len()), | |
|
131 | } | |
|
132 | } | |
|
122 | 133 | } |
|
123 | 134 | |
|
124 | 135 | #[cfg(test)] |
@@ -161,6 +172,7 b' mod tests {' | |||
|
161 | 172 | let mut disco = full_disco(); |
|
162 | 173 | assert_eq!(disco.undecided, None); |
|
163 | 174 | assert!(!disco.has_info()); |
|
175 | assert_eq!(disco.stats().undecided, None); | |
|
164 | 176 | |
|
165 | 177 | disco.add_common_revisions(vec![11, 12])?; |
|
166 | 178 | assert!(disco.has_info()); |
@@ -172,6 +184,7 b' mod tests {' | |||
|
172 | 184 | assert_eq!(disco.undecided, None); |
|
173 | 185 | disco.ensure_undecided()?; |
|
174 | 186 | assert_eq!(sorted_undecided(&disco), vec![5, 8, 10, 13]); |
|
187 | assert_eq!(disco.stats().undecided, Some(4)); | |
|
175 | 188 | Ok(()) |
|
176 | 189 | } |
|
177 | 190 |
@@ -14,7 +14,9 b'' | |||
|
14 | 14 | |
|
15 | 15 | use crate::conversion::{py_set, rev_pyiter_collect}; |
|
16 | 16 | use cindex::Index; |
|
17 | use cpython::{ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python}; | |
|
17 | use cpython::{ | |
|
18 | ObjectProtocol, PyDict, PyModule, PyObject, PyResult, Python, ToPyObject, | |
|
19 | }; | |
|
18 | 20 | use exceptions::GraphError; |
|
19 | 21 | use hg::discovery::PartialDiscovery as CorePartialDiscovery; |
|
20 | 22 | use hg::Revision; |
@@ -83,6 +85,15 b' py_class!(pub class PartialDiscovery |py' | |||
|
83 | 85 | Ok(self.inner(py).borrow().is_complete()) |
|
84 | 86 | } |
|
85 | 87 | |
|
88 | def stats(&self) -> PyResult<PyDict> { | |
|
89 | let stats = self.inner(py).borrow().stats(); | |
|
90 | let as_dict: PyDict = PyDict::new(py); | |
|
91 | as_dict.set_item(py, "undecided", | |
|
92 | stats.undecided.map(|l| l.to_py_object(py)) | |
|
93 | .unwrap_or_else(|| py.None()))?; | |
|
94 | Ok(as_dict) | |
|
95 | } | |
|
96 | ||
|
86 | 97 | def commonheads(&self) -> PyResult<PyObject> { |
|
87 | 98 | py_set( |
|
88 | 99 | py, |
@@ -82,6 +82,14 b' class rustdiscoverytest(unittest.TestCas' | |||
|
82 | 82 | |
|
83 | 83 | self.assertEqual(disco.commonheads(), {1}) |
|
84 | 84 | |
|
85 | def testaddmissingsstats(self): | |
|
86 | idx = self.parseindex() | |
|
87 | disco = PartialDiscovery(idx, [3]) | |
|
88 | self.assertIsNone(disco.stats()['undecided'], None) | |
|
89 | ||
|
90 | disco.addmissings([2]) | |
|
91 | self.assertEqual(disco.stats()['undecided'], 2) | |
|
92 | ||
|
85 | 93 | def testaddinfocommonfirst(self): |
|
86 | 94 | idx = self.parseindex() |
|
87 | 95 | disco = PartialDiscovery(idx, [3]) |
General Comments 0
You need to be logged in to leave comments.
Login now