comparison rust/hg-cpython/src/dirstate/non_normal_entries.rs @ 47094:e061a1df32a8

dirstate-tree: Abstract "non-normal" and "other parent" sets Instead of exposing `HashSet`s directly, have slightly higher-level methods for the operations that Python bindings need on them. Differential Revision: https://phab.mercurial-scm.org/D10363
author Simon Sapin <simon.sapin@octobus.net>
date Thu, 08 Apr 2021 14:58:44 +0200
parents 26114bd6ec60
children cd8ca38fccff
comparison
equal deleted inserted replaced
47093:787ff5d21bcd 47094:e061a1df32a8
5 // This software may be used and distributed according to the terms of the 5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version. 6 // GNU General Public License version 2 or any later version.
7 7
8 use cpython::{ 8 use cpython::{
9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone, 9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone,
10 PyErr, PyList, PyObject, PyResult, PyString, Python, PythonObject, 10 PyErr, PyObject, PyResult, PyString, Python, PythonObject, ToPyObject,
11 ToPyObject, UnsafePyLeaked, 11 UnsafePyLeaked,
12 }; 12 };
13 13
14 use crate::dirstate::DirstateMap; 14 use crate::dirstate::DirstateMap;
15 use hg::utils::hg_path::HgPathBuf; 15 use hg::utils::hg_path::HgPathBuf;
16 use std::cell::RefCell; 16 use std::cell::RefCell;
17 use std::collections::hash_set;
18 17
19 py_class!(pub class NonNormalEntries |py| { 18 py_class!(pub class NonNormalEntries |py| {
20 data dmap: DirstateMap; 19 data dmap: DirstateMap;
21 20
22 def __contains__(&self, key: PyObject) -> PyResult<bool> { 21 def __contains__(&self, key: PyObject) -> PyResult<bool> {
23 self.dmap(py).non_normal_entries_contains(py, key) 22 self.dmap(py).non_normal_entries_contains(py, key)
24 } 23 }
25 def remove(&self, key: PyObject) -> PyResult<PyObject> { 24 def remove(&self, key: PyObject) -> PyResult<PyObject> {
26 self.dmap(py).non_normal_entries_remove(py, key) 25 self.dmap(py).non_normal_entries_remove(py, key)
27 }
28 def union(&self, other: PyObject) -> PyResult<PyList> {
29 self.dmap(py).non_normal_entries_union(py, other)
30 } 26 }
31 def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> { 27 def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> {
32 match op { 28 match op {
33 CompareOp::Eq => self.is_equal_to(py, other), 29 CompareOp::Eq => self.is_equal_to(py, other),
34 CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), 30 CompareOp::Ne => Ok(!self.is_equal_to(py, other)?),
64 ) -> PyResult<Option<PyBytes>> { 60 ) -> PyResult<Option<PyBytes>> {
65 Ok(Some(PyBytes::new(py, key.as_bytes()))) 61 Ok(Some(PyBytes::new(py, key.as_bytes())))
66 } 62 }
67 } 63 }
68 64
69 type NonNormalEntriesIter<'a> = hash_set::Iter<'a, HgPathBuf>; 65 type NonNormalEntriesIter<'a> =
66 Box<dyn Iterator<Item = &'a HgPathBuf> + Send + 'a>;
70 67
71 py_shared_iterator!( 68 py_shared_iterator!(
72 NonNormalEntriesIterator, 69 NonNormalEntriesIterator,
73 UnsafePyLeaked<NonNormalEntriesIter<'static>>, 70 UnsafePyLeaked<NonNormalEntriesIter<'static>>,
74 NonNormalEntries::translate_key, 71 NonNormalEntries::translate_key,