--- a/rust/hg-cpython/src/dirstate/non_normal_entries.rs Sat Sep 07 14:50:39 2019 +0200
+++ b/rust/hg-cpython/src/dirstate/non_normal_entries.rs Mon Feb 24 17:57:57 2020 +0100
@@ -6,11 +6,15 @@
// GNU General Public License version 2 or any later version.
use cpython::{
- exc::NotImplementedError, CompareOp, ObjectProtocol, PyErr, PyList,
- PyObject, PyResult, PyString, Python, PythonObject, ToPyObject,
+ exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone,
+ PyErr, PyList, PyObject, PyResult, PyString, Python, PythonObject,
+ ToPyObject, UnsafePyLeaked,
};
use crate::dirstate::DirstateMap;
+use hg::utils::hg_path::HgPathBuf;
+use std::cell::RefCell;
+use std::collections::hash_set;
py_class!(pub class NonNormalEntries |py| {
data dmap: DirstateMap;
@@ -34,6 +38,10 @@
def __repr__(&self) -> PyResult<PyString> {
self.dmap(py).non_normal_entries_display(py)
}
+
+ def __iter__(&self) -> PyResult<NonNormalEntriesIterator> {
+ self.dmap(py).non_normal_entries_iter(py)
+ }
});
impl NonNormalEntries {
@@ -49,4 +57,20 @@
}
Ok(true)
}
+
+ fn translate_key(
+ py: Python,
+ key: &HgPathBuf,
+ ) -> PyResult<Option<PyBytes>> {
+ Ok(Some(PyBytes::new(py, key.as_ref())))
+ }
}
+
+type NonNormalEntriesIter<'a> = hash_set::Iter<'a, HgPathBuf>;
+
+py_shared_iterator!(
+ NonNormalEntriesIterator,
+ UnsafePyLeaked<NonNormalEntriesIter<'static>>,
+ NonNormalEntries::translate_key,
+ Option<PyBytes>
+);