rust/hg-cpython/src/dirstate/dirstate_map.rs
changeset 42846 01d3ce3281cf
parent 42802 2e1f74cc3350
child 42849 8db8fa1de2ef
equal deleted inserted replaced
42845:f75f47b3ea41 42846:01d3ce3281cf
   167             .iter(py)?
   167             .iter(py)?
   168             .map(|filename| {
   168             .map(|filename| {
   169                 Ok(filename?.extract::<PyBytes>(py)?.data(py).to_owned())
   169                 Ok(filename?.extract::<PyBytes>(py)?.data(py).to_owned())
   170             })
   170             })
   171             .collect();
   171             .collect();
   172         self.inner(py)
   172         self.borrow_mut(py)?
   173             .borrow_mut()
       
   174             .clear_ambiguous_times(files?, now.extract(py)?);
   173             .clear_ambiguous_times(files?, now.extract(py)?);
   175         Ok(py.None())
   174         Ok(py.None())
   176     }
   175     }
   177 
   176 
   178     // TODO share the reference
   177     // TODO share the reference
   203         py.eval("set(non_normal), set(other_parent)", None, Some(&locals))
   202         py.eval("set(non_normal), set(other_parent)", None, Some(&locals))
   204     }
   203     }
   205 
   204 
   206     def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
   205     def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
   207         let d = d.extract::<PyBytes>(py)?;
   206         let d = d.extract::<PyBytes>(py)?;
   208         Ok(self
   207         Ok(self.borrow_mut(py)?
   209             .inner(py)
       
   210             .borrow_mut()
       
   211             .has_tracked_dir(d.data(py))
   208             .has_tracked_dir(d.data(py))
   212             .to_py_object(py))
   209             .to_py_object(py))
   213     }
   210     }
   214 
   211 
   215     def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
   212     def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
   216         let d = d.extract::<PyBytes>(py)?;
   213         let d = d.extract::<PyBytes>(py)?;
   217         Ok(self
   214         Ok(self.borrow_mut(py)?
   218             .inner(py)
       
   219             .borrow_mut()
       
   220             .has_dir(d.data(py))
   215             .has_dir(d.data(py))
   221             .to_py_object(py))
   216             .to_py_object(py))
   222     }
   217     }
   223 
   218 
   224     def parents(&self, st: PyObject) -> PyResult<PyTuple> {
   219     def parents(&self, st: PyObject) -> PyResult<PyTuple> {
   225         self.inner(py)
   220         self.borrow_mut(py)?
   226             .borrow_mut()
       
   227             .parents(st.extract::<PyBytes>(py)?.data(py))
   221             .parents(st.extract::<PyBytes>(py)?.data(py))
   228             .and_then(|d| {
   222             .and_then(|d| {
   229                 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
   223                 Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
   230                     .to_py_object(py))
   224                     .to_py_object(py))
   231             })
   225             })
   239 
   233 
   240     def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> {
   234     def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> {
   241         let p1 = extract_node_id(py, &p1)?;
   235         let p1 = extract_node_id(py, &p1)?;
   242         let p2 = extract_node_id(py, &p2)?;
   236         let p2 = extract_node_id(py, &p2)?;
   243 
   237 
   244         self.inner(py)
   238         self.borrow_mut(py)?
   245             .borrow_mut()
       
   246             .set_parents(&DirstateParents { p1, p2 });
   239             .set_parents(&DirstateParents { p1, p2 });
   247         Ok(py.None())
   240         Ok(py.None())
   248     }
   241     }
   249 
   242 
   250     def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
   243     def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
   251         match self
   244         match self.borrow_mut(py)?
   252             .inner(py)
       
   253             .borrow_mut()
       
   254             .read(st.extract::<PyBytes>(py)?.data(py))
   245             .read(st.extract::<PyBytes>(py)?.data(py))
   255         {
   246         {
   256             Ok(Some(parents)) => Ok(Some(
   247             Ok(Some(parents)) => Ok(Some(
   257                 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2))
   248                 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2))
   258                     .to_py_object(py)
   249                     .to_py_object(py)
   351         )
   342         )
   352     }
   343     }
   353 
   344 
   354     def getdirs(&self) -> PyResult<Dirs> {
   345     def getdirs(&self) -> PyResult<Dirs> {
   355         // TODO don't copy, share the reference
   346         // TODO don't copy, share the reference
   356         self.inner(py).borrow_mut().set_dirs();
   347         self.borrow_mut(py)?.set_dirs();
   357         Dirs::from_inner(
   348         Dirs::from_inner(
   358             py,
   349             py,
   359             DirsMultiset::from_dirstate(
   350             DirsMultiset::from_dirstate(
   360                 &self.inner(py).borrow(),
   351                 &self.inner(py).borrow(),
   361                 Some(EntryState::Removed),
   352                 Some(EntryState::Removed),
   362             ),
   353             ),
   363         )
   354         )
   364     }
   355     }
   365     def getalldirs(&self) -> PyResult<Dirs> {
   356     def getalldirs(&self) -> PyResult<Dirs> {
   366         // TODO don't copy, share the reference
   357         // TODO don't copy, share the reference
   367         self.inner(py).borrow_mut().set_all_dirs();
   358         self.borrow_mut(py)?.set_all_dirs();
   368         Dirs::from_inner(
   359         Dirs::from_inner(
   369             py,
   360             py,
   370             DirsMultiset::from_dirstate(
   361             DirsMultiset::from_dirstate(
   371                 &self.inner(py).borrow(),
   362                 &self.inner(py).borrow(),
   372                 None,
   363                 None,
   420         key: PyObject,
   411         key: PyObject,
   421         value: PyObject
   412         value: PyObject
   422     ) -> PyResult<PyObject> {
   413     ) -> PyResult<PyObject> {
   423         let key = key.extract::<PyBytes>(py)?;
   414         let key = key.extract::<PyBytes>(py)?;
   424         let value = value.extract::<PyBytes>(py)?;
   415         let value = value.extract::<PyBytes>(py)?;
   425         self.inner(py)
   416         self.borrow_mut(py)?
   426             .borrow_mut()
       
   427             .copy_map
   417             .copy_map
   428             .insert(key.data(py).to_vec(), value.data(py).to_vec());
   418             .insert(key.data(py).to_vec(), value.data(py).to_vec());
   429         Ok(py.None())
   419         Ok(py.None())
   430     }
   420     }
   431     def copymappop(
   421     def copymappop(
   432         &self,
   422         &self,
   433         key: PyObject,
   423         key: PyObject,
   434         default: Option<PyObject>
   424         default: Option<PyObject>
   435     ) -> PyResult<Option<PyObject>> {
   425     ) -> PyResult<Option<PyObject>> {
   436         let key = key.extract::<PyBytes>(py)?;
   426         let key = key.extract::<PyBytes>(py)?;
   437         match self.inner(py).borrow_mut().copy_map.remove(key.data(py)) {
   427         match self.borrow_mut(py)?.copy_map.remove(key.data(py)) {
   438             Some(_) => Ok(None),
   428             Some(_) => Ok(None),
   439             None => Ok(default),
   429             None => Ok(default),
   440         }
   430         }
   441     }
   431     }
   442 
   432