annotate rust/hg-cpython/src/dirstate/non_normal_entries.rs @ 44297:cf1f8660e568

rust-dirstatemap: add `NonNormalEntries` class This fix introduces the same encapsulation as the `copymap`. There is no easy way of doing this any better for now. `hg up -r null && time HGRCPATH= HGMODULEPOLICY=rust+c hg up tip` on Mozilla Central, (not super recent, but it doesn't matter): Before: 7:44,08 total After: 1:03,23 total Pretty brutal regression! Differential Revision: https://phab.mercurial-scm.org/D8049
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 10 Feb 2020 21:54:12 +0100
parents
children 8ac5726d695d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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::{
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
9 exc::NotImplementedError, CompareOp, ObjectProtocol, PyErr, PyList,
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
10 PyObject, PyResult, PyString, Python, PythonObject, ToPyObject,
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
11 };
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 use crate::dirstate::DirstateMap;
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
14
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
15 py_class!(pub class NonNormalEntries |py| {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
16 data dmap: DirstateMap;
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
17
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
18 def __contains__(&self, key: PyObject) -> PyResult<bool> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
19 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
20 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
21 def remove(&self, key: PyObject) -> PyResult<PyObject> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
22 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
23 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
24 def union(&self, other: PyObject) -> PyResult<PyList> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
25 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
26 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
27 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
28 match op {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
29 CompareOp::Eq => self.is_equal_to(py, other),
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
30 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
31 _ => Err(PyErr::new::<NotImplementedError, _>(py, ""))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
32 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
33 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
34 def __repr__(&self) -> PyResult<PyString> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
35 self.dmap(py).non_normal_entries_display(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
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
39 impl NonNormalEntries {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
40 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
41 Self::create_instance(py, dm)
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
42 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
43
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
44 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
45 for item in other.iter(py)? {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
46 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
47 return Ok(false);
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
48 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
49 }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
50 Ok(true)
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 }