// non_normal_other_parent_entries.rs // // Copyright 2020 Raphaël Gomès // // 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::{ exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone, PyErr, PyObject, PyResult, PyString, Python, PythonObject, ToPyObject, UnsafePyLeaked, }; use crate::dirstate::DirstateMap; use hg::utils::hg_path::HgPath; use std::cell::RefCell; py_class!(pub class NonNormalEntries |py| { data dmap: DirstateMap; def __contains__(&self, key: PyObject) -> PyResult { self.dmap(py).non_normal_entries_contains(py, key) } def remove(&self, key: PyObject) -> PyResult { self.dmap(py).non_normal_entries_remove(py, key) } def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult { match op { CompareOp::Eq => self.is_equal_to(py, other), CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), _ => Err(PyErr::new::(py, "")) } } def __repr__(&self) -> PyResult { self.dmap(py).non_normal_entries_display(py) } def __iter__(&self) -> PyResult { self.dmap(py).non_normal_entries_iter(py) } }); impl NonNormalEntries { pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult { Self::create_instance(py, dm) } fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult { for item in other.iter(py)? { if !self.dmap(py).non_normal_entries_contains(py, item?)? { return Ok(false); } } Ok(true) } fn translate_key(py: Python, key: &HgPath) -> PyResult> { Ok(Some(PyBytes::new(py, key.as_bytes()))) } } type NonNormalEntriesIter<'a> = Box + Send + 'a>; py_shared_iterator!( NonNormalEntriesIterator, UnsafePyLeaked>, NonNormalEntries::translate_key, Option );