rust/hg-pyo3/src/revlog/mod.rs
changeset 52805 a8debfd85d55
parent 52804 6c6cfb89a4f1
child 52806 0a0ed46ef6d6
equal deleted inserted replaced
52804:6c6cfb89a4f1 52805:a8debfd85d55
     9 #![allow(non_snake_case)]
     9 #![allow(non_snake_case)]
    10 use pyo3::buffer::PyBuffer;
    10 use pyo3::buffer::PyBuffer;
    11 use pyo3::conversion::IntoPyObject;
    11 use pyo3::conversion::IntoPyObject;
    12 use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
    12 use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
    13 use pyo3::prelude::*;
    13 use pyo3::prelude::*;
    14 use pyo3::types::{PyBytes, PyBytesMethods, PyDict, PyList, PySet, PyTuple};
    14 use pyo3::types::{
       
    15     PyBool, PyBytes, PyBytesMethods, PyDict, PyList, PySet, PyTuple,
       
    16 };
    15 use pyo3_sharedref::{PyShareable, SharedByPyObject};
    17 use pyo3_sharedref::{PyShareable, SharedByPyObject};
    16 
    18 
    17 use std::collections::HashSet;
    19 use std::collections::HashSet;
    18 use std::sync::{
    20 use std::sync::{
    19     atomic::{AtomicUsize, Ordering},
    21     atomic::{AtomicUsize, Ordering},
   562         Self::with_index_read(slf, |idx| {
   564         Self::with_index_read(slf, |idx| {
   563             idx.find_snapshots(start_rev.into(), end_rev.into(), &mut cache)
   565             idx.find_snapshots(start_rev.into(), end_rev.into(), &mut cache)
   564                 .map_err(|_| revlog_error_bare())
   566                 .map_err(|_| revlog_error_bare())
   565         })?;
   567         })?;
   566         Ok(())
   568         Ok(())
       
   569     }
       
   570 
       
   571     /// determine revisions with deltas to reconstruct fulltext
       
   572     #[pyo3(signature = (rev, stop_rev, using_general_delta))]
       
   573     fn _index_deltachain(
       
   574         slf: &Bound<'_, Self>,
       
   575         py: Python<'_>,
       
   576         rev: PyRevision,
       
   577         stop_rev: Option<PyRevision>,
       
   578         using_general_delta: Option<u32>,
       
   579     ) -> PyResult<Py<PyTuple>> {
       
   580         let using_general_delta = using_general_delta.map(|i| i != 0);
       
   581         let rev: UncheckedRevision = rev.into();
       
   582         let stop_rev: Option<UncheckedRevision> = stop_rev.map(Into::into);
       
   583 
       
   584         let (chain, stopped) = Self::with_index_read(slf, |idx| {
       
   585             let rev = idx.check_revision(rev).ok_or_else(|| {
       
   586                 nodemap_error(NodeMapError::RevisionNotInIndex(rev))
       
   587             })?;
       
   588             let stop_rev = stop_rev
       
   589                 .map(|r| {
       
   590                     idx.check_revision(r).ok_or_else(|| {
       
   591                         nodemap_error(NodeMapError::RevisionNotInIndex(
       
   592                             rev.into(),
       
   593                         ))
       
   594                     })
       
   595                 })
       
   596                 .transpose()?;
       
   597             idx.delta_chain(rev, stop_rev, using_general_delta)
       
   598                 .map_err(|e| PyValueError::new_err(e.to_string()))
       
   599         })?;
       
   600 
       
   601         let py_chain = revs_py_list(py, chain)?.into_any();
       
   602         let py_stopped =
       
   603             PyBool::new(py, stopped).to_owned().unbind().into_any();
       
   604         Ok((py_chain, py_stopped).into_pyobject(py)?.unbind())
   567     }
   605     }
   568 
   606 
   569     fn _index___len__(slf: &Bound<'_, Self>) -> PyResult<usize> {
   607     fn _index___len__(slf: &Bound<'_, Self>) -> PyResult<usize> {
   570         Self::with_index_read(slf, |idx| Ok(idx.len()))
   608         Self::with_index_read(slf, |idx| Ok(idx.len()))
   571     }
   609     }