rust/hg-cpython/src/discovery.rs
changeset 51243 0993a3520dc6
parent 51242 2e2832e00f6c
child 51245 0b81440e2a73
equal deleted inserted replaced
51242:2e2832e00f6c 51243:0993a3520dc6
   114             ))),
   114             ))),
   115             RefCell::new(index),
   115             RefCell::new(index),
   116         )
   116         )
   117     }
   117     }
   118 
   118 
       
   119     /// Convert a Python iterator of revisions into a vector
       
   120     fn pyiter_to_vec(
       
   121         &self,
       
   122         py: Python,
       
   123         iter: &PyObject,
       
   124     ) -> PyResult<Vec<Revision>> {
       
   125         let index = self.index(py).borrow();
       
   126         rev_pyiter_collect(py, iter, &*index)
       
   127     }
       
   128 
   119     fn inner_addinfo(
   129     fn inner_addinfo(
   120         &self,
   130         &self,
   121         py: Python,
   131         py: Python,
   122         sample: PyObject,
   132         sample: PyObject,
   123     ) -> PyResult<PyObject> {
   133     ) -> PyResult<PyObject> {
   150     fn inner_addcommons(
   160     fn inner_addcommons(
   151         &self,
   161         &self,
   152         py: Python,
   162         py: Python,
   153         commons: PyObject,
   163         commons: PyObject,
   154     ) -> PyResult<PyObject> {
   164     ) -> PyResult<PyObject> {
   155         let index = self.index(py).borrow();
   165         let commons_vec = self.pyiter_to_vec(py, &commons)?;
   156         let commons_vec: Vec<_> = rev_pyiter_collect(py, &commons, &*index)?;
       
   157         let mut inner = self.inner(py).borrow_mut();
   166         let mut inner = self.inner(py).borrow_mut();
   158         inner
   167         inner
   159             .add_common_revisions(commons_vec)
   168             .add_common_revisions(commons_vec)
   160             .map_err(|e| GraphError::pynew(py, e))?;
   169             .map_err(|e| GraphError::pynew(py, e))?;
   161         Ok(py.None())
   170         Ok(py.None())
   164     fn inner_addmissings(
   173     fn inner_addmissings(
   165         &self,
   174         &self,
   166         py: Python,
   175         py: Python,
   167         missings: PyObject,
   176         missings: PyObject,
   168     ) -> PyResult<PyObject> {
   177     ) -> PyResult<PyObject> {
   169         let index = self.index(py).borrow();
   178         let missings_vec = self.pyiter_to_vec(py, &missings)?;
   170         let missings_vec: Vec<_> = rev_pyiter_collect(py, &missings, &*index)?;
       
   171         let mut inner = self.inner(py).borrow_mut();
   179         let mut inner = self.inner(py).borrow_mut();
   172         inner
   180         inner
   173             .add_missing_revisions(missings_vec)
   181             .add_missing_revisions(missings_vec)
   174             .map_err(|e| GraphError::pynew(py, e))?;
   182             .map_err(|e| GraphError::pynew(py, e))?;
   175         Ok(py.None())
   183         Ok(py.None())
   196         &self,
   204         &self,
   197         py: Python,
   205         py: Python,
   198         headrevs: PyObject,
   206         headrevs: PyObject,
   199         size: usize,
   207         size: usize,
   200     ) -> PyResult<PyObject> {
   208     ) -> PyResult<PyObject> {
   201         let index = self.index(py).borrow();
   209         let revsvec = self.pyiter_to_vec(py, &headrevs)?;
   202         let mut inner = self.inner(py).borrow_mut();
   210         let mut inner = self.inner(py).borrow_mut();
   203         let revsvec: Vec<_> = rev_pyiter_collect(py, &headrevs, &*index)?;
       
   204         let sample = inner
   211         let sample = inner
   205             .take_quick_sample(revsvec, size)
   212             .take_quick_sample(revsvec, size)
   206             .map_err(|e| GraphError::pynew(py, e))?;
   213             .map_err(|e| GraphError::pynew(py, e))?;
   207         let as_vec: Vec<PyObject> = sample
   214         let as_vec: Vec<PyObject> = sample
   208             .iter()
   215             .iter()