non_normal_entries.rs
83 lines
| 2.6 KiB
| application/rls-services+xml
|
RustLexer
Raphaël Gomès
|
r44779 | // non_normal_other_parent_entries.rs | ||
// | ||||
// Copyright 2020 Raphaël Gomès <rgomes@octobus.net> | ||||
// | ||||
// This software may be used and distributed according to the terms of the | ||||
// GNU General Public License version 2 or any later version. | ||||
use cpython::{ | ||||
Raphaël Gomès
|
r44903 | exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone, | ||
Simon Sapin
|
r47864 | PyErr, PyObject, PyResult, PyString, Python, PythonObject, ToPyObject, | ||
UnsafePyLeaked, | ||||
Raphaël Gomès
|
r44779 | }; | ||
Simon Sapin
|
r48126 | use crate::dirstate::dirstate_map::v2_error; | ||
Raphaël Gomès
|
r44779 | use crate::dirstate::DirstateMap; | ||
Simon Sapin
|
r48126 | use hg::dirstate_tree::on_disk::DirstateV2ParseError; | ||
Simon Sapin
|
r47894 | use hg::utils::hg_path::HgPath; | ||
Raphaël Gomès
|
r44903 | use std::cell::RefCell; | ||
Raphaël Gomès
|
r44779 | |||
py_class!(pub class NonNormalEntries |py| { | ||||
data dmap: DirstateMap; | ||||
def __contains__(&self, key: PyObject) -> PyResult<bool> { | ||||
self.dmap(py).non_normal_entries_contains(py, key) | ||||
} | ||||
def remove(&self, key: PyObject) -> PyResult<PyObject> { | ||||
self.dmap(py).non_normal_entries_remove(py, key) | ||||
} | ||||
r48492 | def add(&self, key: PyObject) -> PyResult<PyObject> { | |||
self.dmap(py).non_normal_entries_add(py, key) | ||||
} | ||||
def discard(&self, key: PyObject) -> PyResult<PyObject> { | ||||
self.dmap(py).non_normal_entries_discard(py, key) | ||||
} | ||||
Raphaël Gomès
|
r44779 | def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> { | ||
match op { | ||||
CompareOp::Eq => self.is_equal_to(py, other), | ||||
CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), | ||||
_ => Err(PyErr::new::<NotImplementedError, _>(py, "")) | ||||
} | ||||
} | ||||
def __repr__(&self) -> PyResult<PyString> { | ||||
self.dmap(py).non_normal_entries_display(py) | ||||
} | ||||
Raphaël Gomès
|
r44903 | |||
def __iter__(&self) -> PyResult<NonNormalEntriesIterator> { | ||||
self.dmap(py).non_normal_entries_iter(py) | ||||
} | ||||
Raphaël Gomès
|
r44779 | }); | ||
impl NonNormalEntries { | ||||
pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { | ||||
Self::create_instance(py, dm) | ||||
} | ||||
fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult<bool> { | ||||
for item in other.iter(py)? { | ||||
if !self.dmap(py).non_normal_entries_contains(py, item?)? { | ||||
return Ok(false); | ||||
} | ||||
} | ||||
Ok(true) | ||||
} | ||||
Raphaël Gomès
|
r44903 | |||
Simon Sapin
|
r48126 | fn translate_key( | ||
py: Python, | ||||
key: Result<&HgPath, DirstateV2ParseError>, | ||||
) -> PyResult<Option<PyBytes>> { | ||||
let key = key.map_err(|e| v2_error(py, e))?; | ||||
Raphaël Gomès
|
r45500 | Ok(Some(PyBytes::new(py, key.as_bytes()))) | ||
Raphaël Gomès
|
r44903 | } | ||
Raphaël Gomès
|
r44779 | } | ||
Raphaël Gomès
|
r44903 | |||
Simon Sapin
|
r48126 | type NonNormalEntriesIter<'a> = Box< | ||
dyn Iterator<Item = Result<&'a HgPath, DirstateV2ParseError>> + Send + 'a, | ||||
>; | ||||
Raphaël Gomès
|
r44903 | |||
py_shared_iterator!( | ||||
NonNormalEntriesIterator, | ||||
UnsafePyLeaked<NonNormalEntriesIter<'static>>, | ||||
NonNormalEntries::translate_key, | ||||
Option<PyBytes> | ||||
); | ||||