rust/hg-cpython/src/dirstate/dirstate_map.rs
author Raphaël Gomès <rgomes@octobus.net>
Mon, 10 Feb 2020 21:54:12 +0100
changeset 44343 cf1f8660e568
parent 44296 bad4e7b361d2
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! Differential Revision: https://phab.mercurial-scm.org/D8049
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::{
44343
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
    16
    exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList,
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
    17
    PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject,
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
    18
    UnsafePyLeaked,
42770
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
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    21
use crate::{
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    22
    dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
44343
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
    23
    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
    24
    dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
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| {
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
    46
    @shared data inner: 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();
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
    50
        Self::create_instance(py, inner)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    51
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    52
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    53
    def clear(&self) -> PyResult<PyObject> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
    54
        self.inner(py).borrow_mut().clear();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    55
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    57
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
    def get(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    59
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    61
        default: Option<PyObject> = None
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    62
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    63
        let key = key.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
    64
        match self.inner(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
    65
            Some(entry) => {
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
    66
                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
    67
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    68
            None => Ok(default)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    69
        }
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
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    72
    def addfile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    73
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    74
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    75
        oldstate: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    76
        state: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    77
        mode: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    78
        size: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    79
        mtime: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    80
    ) -> PyResult<PyObject> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
    81
        self.inner(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
    82
            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
    83
            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
    84
                .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    85
                .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    86
                    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
    87
                })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    88
            DirstateEntry {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    89
                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
    90
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    91
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    92
                        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
    93
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    94
                mode: mode.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    95
                size: size.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    96
                mtime: mtime.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    97
            },
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
    98
        ).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
    99
            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
   100
        })
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   101
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   102
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   103
    def removefile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   104
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   105
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   106
        oldstate: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   107
        size: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   108
    ) -> PyResult<PyObject> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   109
        self.inner(py).borrow_mut()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   110
            .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
   111
                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
   112
                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
   113
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   114
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   115
                        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
   116
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   117
                size.extract(py)?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   118
            )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   119
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   120
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   121
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   122
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   123
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
            })?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   125
        Ok(py.None())
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
    def dropfile(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   129
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   130
        f: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   131
        oldstate: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   132
    ) -> PyResult<PyBool> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   133
        self.inner(py).borrow_mut()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   134
            .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
   135
                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
   136
                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
   137
                    .try_into()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   138
                    .map_err(|e: DirstateParseError| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   139
                        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
   140
                    })?,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   141
            )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   142
            .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
   143
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   145
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   146
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   147
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   148
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   149
    }
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
    def clearambiguoustimes(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   152
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   153
        files: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   154
        now: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   155
    ) -> 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
   156
        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
   157
            .iter(py)?
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   158
            .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
   159
                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
   160
                    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
   161
                ))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   162
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   163
            .collect();
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   164
        self.inner(py).borrow_mut()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   165
            .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
   166
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   167
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   168
44343
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   169
    def other_parent_entries(&self) -> PyResult<PyObject> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   170
        let mut inner_shared = self.inner(py).borrow_mut();
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   171
        let (_, other_parent) =
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   172
            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
   173
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   174
        let locals = PyDict::new(py);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   175
        locals.set_item(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   176
            py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   177
            "other_parent",
44343
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   178
            other_parent.as_ref()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   179
                .unwrap()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   180
                .iter()
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   181
                .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
   182
                .collect::<Vec<PyBytes>>()
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   183
                .to_py_object(py),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   184
        )?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   185
44343
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   186
        py.eval("set(other_parent)", None, Some(&locals))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   187
    }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   188
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   189
    def non_normal_entries(&self) -> PyResult<NonNormalEntries> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   190
        NonNormalEntries::from_inner(py, self.clone_ref(py))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   191
    }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   192
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   193
    def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   194
        let key = key.extract::<PyBytes>(py)?;
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   195
        Ok(self
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   196
            .inner(py)
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   197
            .borrow_mut()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   198
            .get_non_normal_other_parent_entries().0
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   199
            .as_ref()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   200
            .unwrap()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   201
            .contains(HgPath::new(key.data(py))))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   202
    }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   203
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   204
    def non_normal_entries_display(&self) -> PyResult<PyString> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   205
        Ok(
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   206
            PyString::new(
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   207
                py,
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   208
                &format!(
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   209
                    "NonNormalEntries: {:?}",
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   210
                    self
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   211
                        .inner(py)
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   212
                        .borrow_mut()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   213
                        .get_non_normal_other_parent_entries().0
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   214
                        .as_ref()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   215
                        .unwrap().iter().map(|o| o))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   216
                )
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   217
            )
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   218
    }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   219
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   220
    def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   221
        let key = key.extract::<PyBytes>(py)?;
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   222
        self
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   223
            .inner(py)
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   224
            .borrow_mut()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   225
            .non_normal_entries_remove(HgPath::new(key.data(py)));
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   226
        Ok(py.None())
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   227
    }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   228
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   229
    def non_normal_entries_union(&self, other: PyObject) -> PyResult<PyList> {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   230
        let other: PyResult<_> = other.iter(py)?
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   231
                    .map(|f| {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   232
                        Ok(HgPathBuf::from_bytes(
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   233
                            f?.extract::<PyBytes>(py)?.data(py),
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   234
                        ))
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   235
                    })
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   236
                    .collect();
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   237
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   238
        let res = self
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   239
            .inner(py)
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   240
            .borrow_mut()
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   241
            .non_normal_entries_union(other?);
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   242
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   243
        let ret = PyList::new(py, &[]);
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   244
        for filename in res.iter() {
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   245
            let as_pystring = PyBytes::new(py, filename.as_bytes());
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   246
            ret.append(py, as_pystring.into_object());
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   247
        }
cf1f8660e568 rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents: 44296
diff changeset
   248
        Ok(ret)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   249
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   250
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   251
    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
   252
        let d = d.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   253
        Ok(self.inner(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
   254
            .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
   255
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   256
                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
   257
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   258
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   259
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   260
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
    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
   262
        let d = d.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   263
        Ok(self.inner(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
   264
            .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
   265
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   266
                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
   267
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   268
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   269
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   270
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   271
    def parents(&self, st: PyObject) -> PyResult<PyTuple> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   272
        self.inner(py).borrow_mut()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   273
            .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
   274
            .and_then(|d| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   275
                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
   276
                    .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   277
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   278
            .or_else(|_| {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   279
                Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   280
                    py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   281
                    "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   282
                ))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   283
            })
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   284
    }
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
    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
   287
        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
   288
        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
   289
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   290
        self.inner(py).borrow_mut()
42817
1a535313ad1b rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents: 42816
diff changeset
   291
            .set_parents(&DirstateParents { p1, p2 });
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   292
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   293
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   294
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   295
    def read(&self, st: PyObject) -> PyResult<Option<PyObject>> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   296
        match self.inner(py).borrow_mut()
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   297
            .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
   298
        {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   299
            Ok(Some(parents)) => Ok(Some(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   300
                (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
   301
                    .to_py_object(py)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   302
                    .into_object(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   303
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   304
            Ok(None) => Ok(Some(py.None())),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   305
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   306
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   307
                "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   308
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   309
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   310
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   311
    def write(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   312
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
        p1: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   314
        p2: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   315
        now: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   316
    ) -> PyResult<PyBytes> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   317
        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
   318
        let parents = DirstateParents {
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   319
            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
   320
            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
   321
        };
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   322
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   323
        match self.inner(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
   324
            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
   325
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   326
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   327
                "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   328
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   329
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   330
    }
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
    def filefoldmapasdict(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   333
        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
   334
        for (key, value) in
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   335
            self.inner(py).borrow_mut().build_file_fold_map().iter()
43180
b3dda04e851b rust-cpython: drop self.borrow_mut() in favor of PySharedRef wrapper
Yuya Nishihara <yuya@tcha.org>
parents: 43179
diff changeset
   336
        {
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   337
            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
   338
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   339
        Ok(dict)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   340
    }
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
    def __len__(&self) -> PyResult<usize> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   343
        Ok(self.inner(py).borrow().len())
42770
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
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   346
    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
   347
        let key = key.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   348
        Ok(self.inner(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
   349
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   350
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   351
    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
   352
        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
   353
        let key = HgPath::new(key.data(py));
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   354
        match self.inner(py).borrow().get(key) {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   355
            Some(entry) => {
43208
1ca3823aeefd rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents: 43180
diff changeset
   356
                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
   357
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   358
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   359
                py,
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   360
                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
   361
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   362
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   363
    }
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
    def keys(&self) -> PyResult<DirstateMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   366
        let leaked_ref = self.inner(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   367
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   368
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   369
            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
   370
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   371
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   372
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   373
    def items(&self) -> PyResult<DirstateMapItemsIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   374
        let leaked_ref = self.inner(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   375
        DirstateMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   376
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   377
            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
   378
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   379
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   380
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   381
    def __iter__(&self) -> PyResult<DirstateMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   382
        let leaked_ref = self.inner(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   383
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   384
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   385
            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
   386
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   388
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   389
    def getdirs(&self) -> PyResult<Dirs> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   390
        // TODO don't copy, share the reference
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   391
        self.inner(py).borrow_mut().set_dirs()
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   392
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   393
                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
   394
            })?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   395
        Dirs::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   396
            py,
42818
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42817
diff changeset
   397
            DirsMultiset::from_dirstate(
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   398
                &self.inner(py).borrow(),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
                Some(EntryState::Removed),
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   400
            )
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   401
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   402
                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
   403
            })?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   404
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   405
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   406
    def getalldirs(&self) -> PyResult<Dirs> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   407
        // TODO don't copy, share the reference
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   408
        self.inner(py).borrow_mut().set_all_dirs()
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   409
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   410
                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
   411
            })?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   412
        Dirs::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   413
            py,
42818
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42817
diff changeset
   414
            DirsMultiset::from_dirstate(
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   415
                &self.inner(py).borrow(),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   416
                None,
43874
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   417
            ).map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   418
                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
   419
            })?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   420
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   421
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   422
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   423
    // 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
   424
    def copymapcopy(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   425
        let dict = PyDict::new(py);
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   426
        for (key, value) in self.inner(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
   427
            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
   428
                py,
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   429
                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
   430
                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
   431
            )?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   432
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   433
        Ok(dict)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   434
    }
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
    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
   437
        let key = key.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   438
        match self.inner(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
   439
            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
   440
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   441
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   442
                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
   443
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   444
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   445
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   446
    def copymap(&self) -> PyResult<CopyMap> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   447
        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
   448
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   449
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   450
    def copymaplen(&self) -> PyResult<usize> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   451
        Ok(self.inner(py).borrow().copy_map.len())
42770
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 copymapcontains(&self, key: PyObject) -> PyResult<bool> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   454
        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
   455
        Ok(self
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   456
            .inner(py)
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   457
            .borrow()
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   458
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   459
            .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
   460
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   461
    def copymapget(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   462
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   463
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   464
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   465
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   466
        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
   467
        match self
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   468
            .inner(py)
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   469
            .borrow()
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   470
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   471
            .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
   472
        {
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   473
            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
   474
                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
   475
            )),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   476
            None => Ok(default),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   477
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   478
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   479
    def copymapsetitem(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   480
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   481
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   482
        value: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   483
    ) -> PyResult<PyObject> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   484
        let key = key.extract::<PyBytes>(py)?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   485
        let value = value.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   486
        self.inner(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
   487
            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
   488
            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
   489
        );
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   490
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   491
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   492
    def copymappop(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   493
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   494
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   495
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   496
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   497
        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
   498
        match self
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   499
            .inner(py)
44278
2a24ead003f0 rust-cpython: add panicking version of borrow_mut() and use it
Yuya Nishihara <yuya@tcha.org>
parents: 43874
diff changeset
   500
            .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
   501
            .copy_map
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   502
            .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
   503
        {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   504
            Some(_) => Ok(None),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   505
            None => Ok(default),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   506
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   507
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   508
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   509
    def copymapiter(&self) -> PyResult<CopyMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   510
        let leaked_ref = self.inner(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   511
        CopyMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   512
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   513
            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
   514
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   515
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   516
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   517
    def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   518
        let leaked_ref = self.inner(py).leak_immutable();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   519
        CopyMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   520
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   521
            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
   522
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   523
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   524
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
impl DirstateMap {
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   528
    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
   529
        &'a self,
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   530
        py: Python<'a>,
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   531
    ) -> Ref<'a, RustDirstateMap> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   532
        self.inner(py).borrow()
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   533
    }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   534
    fn translate_key(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   535
        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
   536
        res: (&HgPathBuf, &DirstateEntry),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   537
    ) -> 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
   538
        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
   539
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   540
    fn translate_key_value(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   541
        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
   542
        res: (&HgPathBuf, &DirstateEntry),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   543
    ) -> PyResult<Option<(PyBytes, PyObject)>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   544
        let (f, entry) = res;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   545
        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
   546
            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
   547
            make_dirstate_tuple(py, entry)?,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   548
        )))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   549
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   550
}
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   551
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   552
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   553
    DirstateMapKeysIterator,
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
   554
    UnsafePyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   555
    DirstateMap::translate_key,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   556
    Option<PyBytes>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   557
);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   558
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   559
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   560
    DirstateMapItemsIterator,
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
   561
    UnsafePyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   562
    DirstateMap::translate_key_value,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   563
    Option<(PyBytes, PyObject)>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   564
);
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   565
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   566
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
   567
    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
   568
    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
   569
        Ok(s) => Ok(s),
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   570
        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
   571
    }
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   572
}