Mercurial > hg
annotate rust/hg-cpython/src/dirstate/non_normal_entries.rs @ 44416:8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
This fixes a bug when using `fsmonitor` that tries to iterate on the non normal
set, by adding a shared iterator interface.
Differential Revision: https://phab.mercurial-scm.org/D8143
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 24 Feb 2020 17:57:57 +0100 |
parents | cf1f8660e568 |
children | 26114bd6ec60 |
rev | line source |
---|---|
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 // non_normal_other_parent_entries.rs |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 // |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net> |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 // |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 use cpython::{ |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyBytes, PyClone, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
10 PyErr, PyList, PyObject, PyResult, PyString, Python, PythonObject, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
11 ToPyObject, UnsafePyLeaked, |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 }; |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 use crate::dirstate::DirstateMap; |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
15 use hg::utils::hg_path::HgPathBuf; |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
16 use std::cell::RefCell; |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
17 use std::collections::hash_set; |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 py_class!(pub class NonNormalEntries |py| { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 data dmap: DirstateMap; |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 def __contains__(&self, key: PyObject) -> PyResult<bool> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 self.dmap(py).non_normal_entries_contains(py, key) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 def remove(&self, key: PyObject) -> PyResult<PyObject> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 self.dmap(py).non_normal_entries_remove(py, key) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 def union(&self, other: PyObject) -> PyResult<PyList> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 self.dmap(py).non_normal_entries_union(py, other) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 def __richcmp__(&self, other: PyObject, op: CompareOp) -> PyResult<bool> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 match op { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 CompareOp::Eq => self.is_equal_to(py, other), |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 CompareOp::Ne => Ok(!self.is_equal_to(py, other)?), |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 _ => Err(PyErr::new::<NotImplementedError, _>(py, "")) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 def __repr__(&self) -> PyResult<PyString> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 self.dmap(py).non_normal_entries_display(py) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 } |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
41 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
42 def __iter__(&self) -> PyResult<NonNormalEntriesIterator> { |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
43 self.dmap(py).non_normal_entries_iter(py) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
44 } |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 }); |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 impl NonNormalEntries { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 Self::create_instance(py, dm) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 fn is_equal_to(&self, py: Python, other: PyObject) -> PyResult<bool> { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 for item in other.iter(py)? { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 if !self.dmap(py).non_normal_entries_contains(py, item?)? { |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 return Ok(false); |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 } |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 Ok(true) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 } |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
60 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
61 fn translate_key( |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
62 py: Python, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
63 key: &HgPathBuf, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
64 ) -> PyResult<Option<PyBytes>> { |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
65 Ok(Some(PyBytes::new(py, key.as_ref()))) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
66 } |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 } |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
68 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
69 type NonNormalEntriesIter<'a> = hash_set::Iter<'a, HgPathBuf>; |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
70 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
71 py_shared_iterator!( |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
72 NonNormalEntriesIterator, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
73 UnsafePyLeaked<NonNormalEntriesIter<'static>>, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
74 NonNormalEntries::translate_key, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
75 Option<PyBytes> |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44297
diff
changeset
|
76 ); |