rust/hg-cpython/src/dirstate/dirstate_map.rs
author Raphaël Gomès <rgomes@octobus.net>
Wed, 12 Feb 2020 23:23:59 +0100
branchstable
changeset 44181 71e13cfd6154
parent 43874 bc7d8f45c3b6
child 44196 927137fc3035
child 44393 a69c08cdb2a8
permissions -rw-r--r--
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! This is a graft on stable of cf1f8660e568 Differential Revision: https://phab.mercurial-scm.org/D8111
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     1
// dirstate_map.rs
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     2
//
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     3
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     4
//
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     5
// This software may be used and distributed according to the terms of the
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     6
// GNU General Public License version 2 or any later version.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     7
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     8
//! Bindings for the `hg::dirstate::dirstate_map` file provided by the
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     9
//! `hg-core` package.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    10
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
    11
use std::cell::{Ref, RefCell};
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    12
use std::convert::TryInto;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    13
use std::time::Duration;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    14
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    15
use cpython::{
44181
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
    16
    exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList,
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
    17
    PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    18
};
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    19
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    20
use crate::{
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    21
    dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
44181
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
    22
    dirstate::non_normal_entries::NonNormalEntries,
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
    23
    dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
43474
b9f791090211 rust-cpython: rename PyLeakedRef to PyLeaked
Yuya Nishihara <yuya@tcha.org>
parents: 43286
diff changeset
    24
    ref_sharing::{PyLeaked, PySharedRefCell},
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    25
};
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    26
use hg::{
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
    27
    utils::hg_path::{HgPath, HgPathBuf},
42818
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42817
diff changeset
    28
    DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap,
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43482
diff changeset
    29
    DirstateMapError, DirstateParents, DirstateParseError, EntryState,
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43482
diff changeset
    30
    StateMapIter, PARENT_SIZE,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    31
};
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    32
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    33
// TODO
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    34
//     This object needs to share references to multiple members of its Rust
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    35
//     inner struct, namely `copy_map`, `dirs` and `all_dirs`.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    36
//     Right now `CopyMap` is done, but it needs to have an explicit reference
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
//     to `RustDirstateMap` which itself needs to have an encapsulation for
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    38
//     every method in `CopyMap` (copymapcopy, etc.).
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    39
//     This is ugly and hard to maintain.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    40
//     The same logic applies to `dirs` and `all_dirs`, however the `Dirs`
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    41
//     `py_class!` is already implemented and does not mention
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    42
//     `RustDirstateMap`, rightfully so.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    43
//     All attributes also have to have a separate refcount data attribute for
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    44
//     leaks, with all methods that go along for reference sharing.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    45
py_class!(pub class DirstateMap |py| {
42855
8db8fa1de2ef rust-cpython: introduce restricted variant of RefCell
Yuya Nishihara <yuya@tcha.org>
parents: 42854
diff changeset
    46
    data inner: PySharedRefCell<RustDirstateMap>;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    47
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    48
    def __new__(_cls, _root: PyObject) -> PyResult<Self> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    49
        let inner = RustDirstateMap::default();
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    50
        Self::create_instance(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    51
            py,
42855
8db8fa1de2ef rust-cpython: introduce restricted variant of RefCell
Yuya Nishihara <yuya@tcha.org>
parents: 42854
diff changeset
    52
            PySharedRefCell::new(inner),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    53
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    54
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    55
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
    def clear(&self) -> PyResult<PyObject> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
    57
        self.inner_shared(py).borrow_mut()?.clear();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    59
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    61
    def get(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    62
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    63
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    64
        default: Option<PyObject> = None
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    65
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    66
        let key = key.extract::<PyBytes>(py)?;
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
    67
        match self.inner_shared(py).borrow().get(HgPath::new(key.data(py))) {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    68
            Some(entry) => {
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
    69
                Ok(Some(make_dirstate_tuple(py, entry)?))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    70
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    71
            None => Ok(default)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    72
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    73
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    74
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    75
    def addfile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    76
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    77
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    78
        oldstate: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    79
        state: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    80
        mode: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    81
        size: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    82
        mtime: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    83
    ) -> PyResult<PyObject> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
    84
        self.inner_shared(py).borrow_mut()?.add_file(
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
    85
            HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    86
            oldstate.extract::<PyBytes>(py)?.data(py)[0]
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    87
                .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    88
                .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    89
                    PyErr::new::<exc::ValueError, _>(py, e.to_string())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    90
                })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    91
            DirstateEntry {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    92
                state: state.extract::<PyBytes>(py)?.data(py)[0]
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    93
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    94
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    95
                        PyErr::new::<exc::ValueError, _>(py, e.to_string())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    96
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    97
                mode: mode.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    98
                size: size.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    99
                mtime: mtime.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   100
            },
43808
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43482
diff changeset
   101
        ).and(Ok(py.None())).or_else(|e: DirstateMapError| {
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43482
diff changeset
   102
            Err(PyErr::new::<exc::ValueError, _>(py, e.to_string()))
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43482
diff changeset
   103
        })
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   104
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   105
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   106
    def removefile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   107
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   108
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   109
        oldstate: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   110
        size: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   111
    ) -> PyResult<PyObject> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   112
        self.inner_shared(py).borrow_mut()?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   113
            .remove_file(
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   114
                HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   115
                oldstate.extract::<PyBytes>(py)?.data(py)[0]
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   116
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   117
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   118
                        PyErr::new::<exc::ValueError, _>(py, e.to_string())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   119
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   120
                size.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   121
            )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   122
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   123
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   125
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   126
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   127
            })?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   128
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   129
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   130
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   131
    def dropfile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   132
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   133
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   134
        oldstate: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   135
    ) -> PyResult<PyBool> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   136
        self.inner_shared(py).borrow_mut()?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   137
            .drop_file(
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   138
                HgPath::new(f.extract::<PyBytes>(py)?.data(py)),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   139
                oldstate.extract::<PyBytes>(py)?.data(py)[0]
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   140
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   141
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   142
                        PyErr::new::<exc::ValueError, _>(py, e.to_string())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   143
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
            )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   145
            .and_then(|b| Ok(b.to_py_object(py)))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   146
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   147
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   148
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   149
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   150
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   151
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   152
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   153
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   154
    def clearambiguoustimes(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   155
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   156
        files: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   157
        now: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   158
    ) -> PyResult<PyObject> {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   159
        let files: PyResult<Vec<HgPathBuf>> = files
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   160
            .iter(py)?
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   161
            .map(|filename| {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   162
                Ok(HgPathBuf::from_bytes(
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   163
                    filename?.extract::<PyBytes>(py)?.data(py),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   164
                ))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   165
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   166
            .collect();
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   167
        self.inner_shared(py).borrow_mut()?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   168
            .clear_ambiguous_times(files?, now.extract(py)?);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   169
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   170
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   171
44181
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   172
    def other_parent_entries(&self) -> PyResult<PyObject> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   173
        let mut inner_shared = self.inner_shared(py).borrow_mut()?;
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   174
        let (_, other_parent) =
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   175
            inner_shared.get_non_normal_other_parent_entries();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   176
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   177
        let locals = PyDict::new(py);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   178
        locals.set_item(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   179
            py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   180
            "other_parent",
44181
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   181
            other_parent.as_ref()
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   182
                .unwrap()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   183
                .iter()
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   184
                .map(|v| PyBytes::new(py, v.as_ref()))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   185
                .collect::<Vec<PyBytes>>()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   186
                .to_py_object(py),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   187
        )?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   188
44181
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   189
        py.eval("set(other_parent)", None, Some(&locals))
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   190
    }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   191
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   192
    def non_normal_entries(&self) -> PyResult<NonNormalEntries> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   193
        NonNormalEntries::from_inner(py, self.clone_ref(py))
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   194
    }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   195
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   196
    def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   197
        let key = key.extract::<PyBytes>(py)?;
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   198
        Ok(self
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   199
            .inner_shared(py)
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   200
            .borrow_mut()?
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   201
            .get_non_normal_other_parent_entries().0
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   202
            .as_ref()
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   203
            .unwrap()
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   204
            .contains(HgPath::new(key.data(py))))
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   205
    }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   206
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   207
    def non_normal_entries_display(&self) -> PyResult<PyString> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   208
        Ok(
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   209
            PyString::new(
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   210
                py,
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   211
                &format!(
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   212
                    "NonNormalEntries: {:?}",
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   213
                    self
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   214
                        .inner_shared(py)
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   215
                        .borrow_mut()?
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   216
                        .get_non_normal_other_parent_entries().0
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   217
                        .as_ref()
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   218
                        .unwrap().iter().map(|o| o))
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   219
                )
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   220
            )
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   221
    }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   222
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   223
    def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   224
        let key = key.extract::<PyBytes>(py)?;
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   225
        self
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   226
            .inner_shared(py)
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   227
            .borrow_mut()?
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   228
            .non_normal_entries_remove(HgPath::new(key.data(py)));
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   229
        Ok(py.None())
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   230
    }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   231
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   232
    def non_normal_entries_union(&self, other: PyObject) -> PyResult<PyList> {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   233
        let other: PyResult<_> = other.iter(py)?
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   234
                    .map(|f| {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   235
                        Ok(HgPathBuf::from_bytes(
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   236
                            f?.extract::<PyBytes>(py)?.data(py),
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   237
                        ))
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   238
                    })
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   239
                    .collect();
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   240
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   241
        let res = self
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   242
            .inner_shared(py)
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   243
            .borrow_mut()?
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   244
            .non_normal_entries_union(other?);
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   245
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   246
        let ret = PyList::new(py, &[]);
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   247
        for (i, filename) in res.iter().enumerate() {
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   248
            let as_pystring = PyBytes::new(py, filename.as_bytes());
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   249
            ret.insert_item(py, i, as_pystring.into_object());
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   250
        }
71e13cfd6154 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 43874
diff changeset
   251
        Ok(ret)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   252
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   253
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   254
    def hastrackeddir(&self, d: PyObject) -> PyResult<PyBool> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   255
        let d = d.extract::<PyBytes>(py)?;
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   256
        Ok(self.inner_shared(py).borrow_mut()?
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   257
            .has_tracked_dir(HgPath::new(d.data(py)))
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   258
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   259
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   260
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   262
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   263
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   264
    def hasdir(&self, d: PyObject) -> PyResult<PyBool> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   265
        let d = d.extract::<PyBytes>(py)?;
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   266
        Ok(self.inner_shared(py).borrow_mut()?
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   267
            .has_dir(HgPath::new(d.data(py)))
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   268
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   269
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   270
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   271
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   272
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   273
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   274
    def parents(&self, st: PyObject) -> PyResult<PyTuple> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   275
        self.inner_shared(py).borrow_mut()?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   276
            .parents(st.extract::<PyBytes>(py)?.data(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   277
            .and_then(|d| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   278
                Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   279
                    .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   280
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   281
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   282
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   283
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   284
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   285
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   286
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   287
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   288
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   289
    def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> {
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   290
        let p1 = extract_node_id(py, &p1)?;
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   291
        let p2 = extract_node_id(py, &p2)?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   292
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   293
        self.inner_shared(py).borrow_mut()?
42817
1a535313ad1b rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents: 42816
diff changeset
   294
            .set_parents(&DirstateParents { p1, p2 });
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   295
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   296
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   297
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   298
    def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   299
        match self.inner_shared(py).borrow_mut()?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   300
            .read(st.extract::<PyBytes>(py)?.data(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   301
        {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   302
            Ok(Some(parents)) => Ok(Some(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   303
                (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   304
                    .to_py_object(py)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   305
                    .into_object(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   306
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   307
            Ok(None) => Ok(Some(py.None())),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   308
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   309
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   310
                "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   311
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   312
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   314
    def write(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   315
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   316
        p1: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   317
        p2: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   318
        now: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   319
    ) -> PyResult<PyBytes> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   320
        let now = Duration::new(now.extract(py)?, 0);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   321
        let parents = DirstateParents {
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   322
            p1: extract_node_id(py, &p1)?,
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   323
            p2: extract_node_id(py, &p2)?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   324
        };
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   325
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   326
        match self.inner_shared(py).borrow_mut()?.pack(parents, now) {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   327
            Ok(packed) => Ok(PyBytes::new(py, &packed)),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   328
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   329
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   330
                "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   331
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   332
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   333
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   334
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   335
    def filefoldmapasdict(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   336
        let dict = PyDict::new(py);
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   337
        for (key, value) in
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   338
            self.inner_shared(py).borrow_mut()?.build_file_fold_map().iter()
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   339
        {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   340
            dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   341
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   342
        Ok(dict)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   343
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   344
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   345
    def __len__(&self) -> PyResult<usize> {
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   346
        Ok(self.inner_shared(py).borrow().len())
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   347
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   348
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   349
    def __contains__(&self, key: PyObject) -> PyResult<bool> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   350
        let key = key.extract::<PyBytes>(py)?;
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   351
        Ok(self.inner_shared(py).borrow().contains_key(HgPath::new(key.data(py))))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   352
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   353
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   354
    def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   355
        let key = key.extract::<PyBytes>(py)?;
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   356
        let key = HgPath::new(key.data(py));
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   357
        match self.inner_shared(py).borrow().get(key) {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   358
            Some(entry) => {
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
   359
                Ok(make_dirstate_tuple(py, entry)?)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   360
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   361
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   362
                py,
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   363
                String::from_utf8_lossy(key.as_bytes()),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   364
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   365
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   366
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   367
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   368
    def keys(&self) -> PyResult<DirstateMapKeysIterator> {
43482
8418b77132c1 rust-cpython: remove useless PyResult<> from leak_immutable()
Yuya Nishihara <yuya@tcha.org>
parents: 43474
diff changeset
   369
        let leaked_ref = self.inner_shared(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   370
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   371
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   372
            unsafe { leaked_ref.map(py, |o| o.iter()) },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   373
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   374
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   375
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   376
    def items(&self) -> PyResult<DirstateMapItemsIterator> {
43482
8418b77132c1 rust-cpython: remove useless PyResult<> from leak_immutable()
Yuya Nishihara <yuya@tcha.org>
parents: 43474
diff changeset
   377
        let leaked_ref = self.inner_shared(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   378
        DirstateMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   379
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   380
            unsafe { leaked_ref.map(py, |o| o.iter()) },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   381
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   382
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   383
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   384
    def __iter__(&self) -> PyResult<DirstateMapKeysIterator> {
43482
8418b77132c1 rust-cpython: remove useless PyResult<> from leak_immutable()
Yuya Nishihara <yuya@tcha.org>
parents: 43474
diff changeset
   385
        let leaked_ref = self.inner_shared(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   386
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   388
            unsafe { leaked_ref.map(py, |o| o.iter()) },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   389
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   390
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   391
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   392
    def getdirs(&self) -> PyResult<Dirs> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   393
        // TODO don't copy, share the reference
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   394
        self.inner_shared(py).borrow_mut()?.set_dirs()
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   395
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   396
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   397
            })?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   398
        Dirs::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
            py,
42818
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42817
diff changeset
   400
            DirsMultiset::from_dirstate(
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   401
                &self.inner_shared(py).borrow(),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   402
                Some(EntryState::Removed),
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   403
            )
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   404
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   405
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   406
            })?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   407
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   408
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   409
    def getalldirs(&self) -> PyResult<Dirs> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   410
        // TODO don't copy, share the reference
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   411
        self.inner_shared(py).borrow_mut()?.set_all_dirs()
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   412
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   413
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   414
            })?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   415
        Dirs::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   416
            py,
42818
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42817
diff changeset
   417
            DirsMultiset::from_dirstate(
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   418
                &self.inner_shared(py).borrow(),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   419
                None,
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   420
            ).map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   421
                PyErr::new::<exc::ValueError, _>(py, e.to_string())
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   422
            })?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   423
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   424
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   425
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   426
    // TODO all copymap* methods, see docstring above
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   427
    def copymapcopy(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   428
        let dict = PyDict::new(py);
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   429
        for (key, value) in self.inner_shared(py).borrow().copy_map.iter() {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   430
            dict.set_item(
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   431
                py,
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   432
                PyBytes::new(py, key.as_ref()),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   433
                PyBytes::new(py, value.as_ref()),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   434
            )?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   435
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   436
        Ok(dict)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   437
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   438
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   439
    def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   440
        let key = key.extract::<PyBytes>(py)?;
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   441
        match self.inner_shared(py).borrow().copy_map.get(HgPath::new(key.data(py))) {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   442
            Some(copy) => Ok(PyBytes::new(py, copy.as_ref())),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   443
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   444
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   445
                String::from_utf8_lossy(key.data(py)),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   446
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   447
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   448
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   449
    def copymap(&self) -> PyResult<CopyMap> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   450
        CopyMap::from_inner(py, self.clone_ref(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   451
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   452
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   453
    def copymaplen(&self) -> PyResult<usize> {
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   454
        Ok(self.inner_shared(py).borrow().copy_map.len())
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   455
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   456
    def copymapcontains(&self, key: PyObject) -> PyResult<bool> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   457
        let key = key.extract::<PyBytes>(py)?;
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   458
        Ok(self
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   459
            .inner_shared(py)
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   460
            .borrow()
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   461
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   462
            .contains_key(HgPath::new(key.data(py))))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   463
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   464
    def copymapget(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   465
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   466
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   467
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   468
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   469
        let key = key.extract::<PyBytes>(py)?;
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   470
        match self
43286
f8c114f20d2d rust-cpython: require GIL to borrow immutable reference from PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 43285
diff changeset
   471
            .inner_shared(py)
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   472
            .borrow()
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   473
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   474
            .get(HgPath::new(key.data(py)))
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   475
        {
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   476
            Some(copy) => Ok(Some(
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   477
                PyBytes::new(py, copy.as_ref()).into_object(),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   478
            )),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   479
            None => Ok(default),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   480
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   481
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   482
    def copymapsetitem(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   483
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   484
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   485
        value: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   486
    ) -> PyResult<PyObject> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   487
        let key = key.extract::<PyBytes>(py)?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   488
        let value = value.extract::<PyBytes>(py)?;
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   489
        self.inner_shared(py).borrow_mut()?.copy_map.insert(
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   490
            HgPathBuf::from_bytes(key.data(py)),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   491
            HgPathBuf::from_bytes(value.data(py)),
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   492
        );
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   493
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   494
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   495
    def copymappop(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   496
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   497
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   498
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   499
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   500
        let key = key.extract::<PyBytes>(py)?;
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   501
        match self
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   502
            .inner_shared(py)
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   503
            .borrow_mut()?
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   504
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   505
            .remove(HgPath::new(key.data(py)))
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   506
        {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   507
            Some(_) => Ok(None),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   508
            None => Ok(default),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   509
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   510
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   511
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   512
    def copymapiter(&self) -> PyResult<CopyMapKeysIterator> {
43482
8418b77132c1 rust-cpython: remove useless PyResult<> from leak_immutable()
Yuya Nishihara <yuya@tcha.org>
parents: 43474
diff changeset
   513
        let leaked_ref = self.inner_shared(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   514
        CopyMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   515
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   516
            unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   517
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   518
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   519
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   520
    def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> {
43482
8418b77132c1 rust-cpython: remove useless PyResult<> from leak_immutable()
Yuya Nishihara <yuya@tcha.org>
parents: 43474
diff changeset
   521
        let leaked_ref = self.inner_shared(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   522
        CopyMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   523
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   524
            unsafe { leaked_ref.map(py, |o| o.copy_map.iter()) },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   525
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   526
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   527
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   528
});
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   529
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   530
impl DirstateMap {
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   531
    pub fn get_inner<'a>(
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   532
        &'a self,
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   533
        py: Python<'a>,
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   534
    ) -> Ref<'a, RustDirstateMap> {
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   535
        self.inner_shared(py).borrow()
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   536
    }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   537
    fn translate_key(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   538
        py: Python,
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   539
        res: (&HgPathBuf, &DirstateEntry),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   540
    ) -> PyResult<Option<PyBytes>> {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   541
        Ok(Some(PyBytes::new(py, res.0.as_ref())))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   542
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   543
    fn translate_key_value(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   544
        py: Python,
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   545
        res: (&HgPathBuf, &DirstateEntry),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   546
    ) -> PyResult<Option<(PyBytes, PyObject)>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   547
        let (f, entry) = res;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   548
        Ok(Some((
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   549
            PyBytes::new(py, f.as_ref()),
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
   550
            make_dirstate_tuple(py, entry)?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   551
        )))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   552
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   553
}
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   554
43178
1b2200bd06b6 rust-cpython: add safe wrapper representing shared data borrowed from PyObject
Yuya Nishihara <yuya@tcha.org>
parents: 43177
diff changeset
   555
py_shared_ref!(DirstateMap, RustDirstateMap, inner, inner_shared);
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   556
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   557
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   558
    DirstateMapKeysIterator,
43474
b9f791090211 rust-cpython: rename PyLeakedRef to PyLeaked
Yuya Nishihara <yuya@tcha.org>
parents: 43286
diff changeset
   559
    PyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   560
    DirstateMap::translate_key,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   561
    Option<PyBytes>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   562
);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   563
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   564
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   565
    DirstateMapItemsIterator,
43474
b9f791090211 rust-cpython: rename PyLeakedRef to PyLeaked
Yuya Nishihara <yuya@tcha.org>
parents: 43286
diff changeset
   566
    PyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   567
    DirstateMap::translate_key_value,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   568
    Option<(PyBytes, PyObject)>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   569
);
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   570
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   571
fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> {
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   572
    let bytes = obj.extract::<PyBytes>(py)?;
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   573
    match bytes.data(py).try_into() {
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   574
        Ok(s) => Ok(s),
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   575
        Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())),
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   576
    }
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   577
}