##// END OF EJS Templates
dirstate-tree: Add tree traversal/iteration...
dirstate-tree: Add tree traversal/iteration Like Python’s, Rust’s iterators are "external" in that they are driven by a caller who calls a `next` method. This is as opposed to "internal" iterators who drive themselves and call a callback for each item. Writing an internal iterator traversing a tree is easy with recursion, but internal iterators cannot rely on the call stack in that way, they must save in an explicit object all state that they need to be preserved across two `next` calls. This algorithm uses a `Vec` as a stack that contains what would be local variables on the call stack if we could use recursion. Differential Revision: https://phab.mercurial-scm.org/D10370

File last commit:

r47864:e061a1df default
r47870:caa3031c default
Show More
non_normal_entries.rs
73 lines | 2.2 KiB | application/rls-services+xml | RustLexer
/ rust / hg-cpython / src / dirstate / non_normal_entries.rs
Raphaël Gomès
rust-dirstatemap: add `NonNormalEntries` class...
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
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903 exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone,
Simon Sapin
dirstate-tree: Abstract "non-normal" and "other parent" sets...
r47864 PyErr, PyObject, PyResult, PyString, Python, PythonObject, ToPyObject,
UnsafePyLeaked,
Raphaël Gomès
rust-dirstatemap: add `NonNormalEntries` class...
r44779 };
use crate::dirstate::DirstateMap;
Raphaël Gomès
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903 use hg::utils::hg_path::HgPathBuf;
use std::cell::RefCell;
Raphaël Gomès
rust-dirstatemap: add `NonNormalEntries` class...
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)
}
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
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903
def __iter__(&self) -> PyResult<NonNormalEntriesIterator> {
self.dmap(py).non_normal_entries_iter(py)
}
Raphaël Gomès
rust-dirstatemap: add `NonNormalEntries` class...
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
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903
fn translate_key(
py: Python,
key: &HgPathBuf,
) -> PyResult<Option<PyBytes>> {
Raphaël Gomès
rust: do a clippy pass...
r45500 Ok(Some(PyBytes::new(py, key.as_bytes())))
Raphaël Gomès
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903 }
Raphaël Gomès
rust-dirstatemap: add `NonNormalEntries` class...
r44779 }
Raphaël Gomès
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903
Simon Sapin
dirstate-tree: Abstract "non-normal" and "other parent" sets...
r47864 type NonNormalEntriesIter<'a> =
Box<dyn Iterator<Item = &'a HgPathBuf> + Send + 'a>;
Raphaël Gomès
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)...
r44903
py_shared_iterator!(
NonNormalEntriesIterator,
UnsafePyLeaked<NonNormalEntriesIter<'static>>,
NonNormalEntries::translate_key,
Option<PyBytes>
);