##// END OF EJS Templates
rust-discovery: implementing and exposing stats()...
Georges Racinet -
r42357:1b0be75c default
parent child Browse files
Show More
@@ -23,6 +23,10 b' pub struct PartialDiscovery<G: Graph + C'
23 missing: HashSet<Revision>,
23 missing: HashSet<Revision>,
24 }
24 }
25
25
26 pub struct DiscoveryStats {
27 pub undecided: Option<usize>,
28 }
29
26 impl<G: Graph + Clone> PartialDiscovery<G> {
30 impl<G: Graph + Clone> PartialDiscovery<G> {
27 /// Create a PartialDiscovery object, with the intent
31 /// Create a PartialDiscovery object, with the intent
28 /// of comparing our `::<target_heads>` revset to the contents of another
32 /// of comparing our `::<target_heads>` revset to the contents of another
@@ -119,6 +123,13 b' impl<G: Graph + Clone> PartialDiscovery<'
119 Some(self.common.missing_ancestors(tgt)?.into_iter().collect());
123 Some(self.common.missing_ancestors(tgt)?.into_iter().collect());
120 Ok(())
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 #[cfg(test)]
135 #[cfg(test)]
@@ -161,6 +172,7 b' mod tests {'
161 let mut disco = full_disco();
172 let mut disco = full_disco();
162 assert_eq!(disco.undecided, None);
173 assert_eq!(disco.undecided, None);
163 assert!(!disco.has_info());
174 assert!(!disco.has_info());
175 assert_eq!(disco.stats().undecided, None);
164
176
165 disco.add_common_revisions(vec![11, 12])?;
177 disco.add_common_revisions(vec![11, 12])?;
166 assert!(disco.has_info());
178 assert!(disco.has_info());
@@ -172,6 +184,7 b' mod tests {'
172 assert_eq!(disco.undecided, None);
184 assert_eq!(disco.undecided, None);
173 disco.ensure_undecided()?;
185 disco.ensure_undecided()?;
174 assert_eq!(sorted_undecided(&disco), vec![5, 8, 10, 13]);
186 assert_eq!(sorted_undecided(&disco), vec![5, 8, 10, 13]);
187 assert_eq!(disco.stats().undecided, Some(4));
175 Ok(())
188 Ok(())
176 }
189 }
177
190
@@ -14,7 +14,9 b''
14
14
15 use crate::conversion::{py_set, rev_pyiter_collect};
15 use crate::conversion::{py_set, rev_pyiter_collect};
16 use cindex::Index;
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 use exceptions::GraphError;
20 use exceptions::GraphError;
19 use hg::discovery::PartialDiscovery as CorePartialDiscovery;
21 use hg::discovery::PartialDiscovery as CorePartialDiscovery;
20 use hg::Revision;
22 use hg::Revision;
@@ -83,6 +85,15 b' py_class!(pub class PartialDiscovery |py'
83 Ok(self.inner(py).borrow().is_complete())
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 def commonheads(&self) -> PyResult<PyObject> {
97 def commonheads(&self) -> PyResult<PyObject> {
87 py_set(
98 py_set(
88 py,
99 py,
@@ -82,6 +82,14 b' class rustdiscoverytest(unittest.TestCas'
82
82
83 self.assertEqual(disco.commonheads(), {1})
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 def testaddinfocommonfirst(self):
93 def testaddinfocommonfirst(self):
86 idx = self.parseindex()
94 idx = self.parseindex()
87 disco = PartialDiscovery(idx, [3])
95 disco = PartialDiscovery(idx, [3])
General Comments 0
You need to be logged in to leave comments. Login now