rust/hg-cpython/src/dirstate/dirstate_map.rs
author Raphaël Gomès <rgomes@octobus.net>
Mon, 14 Nov 2022 15:20:48 +0100
changeset 49749 c7fb9b74e753
parent 49200 10b9f11daf15
child 49987 58074252db3c
permissions -rw-r--r--
rust: remove newly redundant `use` statements with the 2021 edition prelude https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
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
47126
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47123
diff changeset
    11
use std::cell::{RefCell, RefMut};
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    12
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    13
use cpython::{
48071
cd13d3c2ad2e dirstate: drop the `clearambiguoustimes` method for the map
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48066
diff changeset
    14
    exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject,
48076
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48071
diff changeset
    15
    PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    16
};
49156
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
    17
use hg::dirstate::{ParentFileData, TruncatedTimestamp};
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    18
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    19
use crate::{
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    20
    dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
    21
    dirstate::item::DirstateItem,
47982
4afd6cc447b9 rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents: 47692
diff changeset
    22
    pybytes_deref::PyBytesDeref,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    23
};
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    24
use hg::{
49179
d9a66d62c604 rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents: 49177
diff changeset
    25
    dirstate::StateMapIter, dirstate_tree::on_disk::DirstateV2ParseError,
d9a66d62c604 rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents: 49177
diff changeset
    26
    dirstate_tree::owning::OwningDirstateMap, revlog::Node,
d9a66d62c604 rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents: 49177
diff changeset
    27
    utils::files::normalize_case, utils::hg_path::HgPath, DirstateEntry,
49190
a1fce5003ff4 rust-hg-cpython: remove use of `EntryState`
Raphaël Gomès <rgomes@octobus.net>
parents: 49179
diff changeset
    28
    DirstateError, DirstateParents,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    29
};
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    30
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    31
// TODO
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    32
//     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
    33
//     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
    34
//     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
    35
//     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
    36
//     every method in `CopyMap` (copymapcopy, etc.).
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
//     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
    38
//     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
    39
//     `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
    40
//     `RustDirstateMap`, rightfully so.
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    41
//     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
    42
//     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
    43
py_class!(pub class DirstateMap |py| {
48084
3d0a9c6e614d dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents: 48083
diff changeset
    44
    @shared data inner: OwningDirstateMap;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    45
47136
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47135
diff changeset
    46
    /// Returns a `(dirstate_map, parents)` tuple
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47135
diff changeset
    47
    @staticmethod
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    48
    def new_v1(
47291
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47138
diff changeset
    49
        on_disk: PyBytes,
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47138
diff changeset
    50
    ) -> PyResult<PyObject> {
48083
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 48076
diff changeset
    51
        let on_disk = PyBytesDeref::new(py, on_disk);
48825
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48467
diff changeset
    52
        let (map, parents) = OwningDirstateMap::new_v1(on_disk)
48083
bf8837e3d7ce dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents: 48076
diff changeset
    53
            .map_err(|e| dirstate_error(py, e))?;
48084
3d0a9c6e614d dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents: 48083
diff changeset
    54
        let map = Self::create_instance(py, map)?;
48825
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48467
diff changeset
    55
        let p1 = PyBytes::new(py, parents.p1.as_bytes());
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48467
diff changeset
    56
        let p2 = PyBytes::new(py, parents.p2.as_bytes());
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48467
diff changeset
    57
        let parents = (p1, p2);
47136
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47135
diff changeset
    58
        Ok((map, parents).to_py_object(py).into_object())
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    59
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    61
    /// Returns a DirstateMap
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    62
    @staticmethod
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    63
    def new_v2(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    64
        on_disk: PyBytes,
47675
48aec076b8fb dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
    65
        data_size: usize,
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
    66
        tree_metadata: PyBytes,
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    67
    ) -> PyResult<PyObject> {
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    68
        let dirstate_error = |e: DirstateError| {
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    69
            PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e))
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    70
        };
47982
4afd6cc447b9 rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents: 47692
diff changeset
    71
        let on_disk = PyBytesDeref::new(py, on_disk);
48825
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48467
diff changeset
    72
        let map = OwningDirstateMap::new_v2(
47982
4afd6cc447b9 rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents: 47692
diff changeset
    73
            on_disk, data_size, tree_metadata.data(py),
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
    74
        ).map_err(dirstate_error)?;
48084
3d0a9c6e614d dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents: 48083
diff changeset
    75
        let map = Self::create_instance(py, map)?;
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    76
        Ok(map.into_object())
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    77
    }
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
    78
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    79
    def clear(&self) -> PyResult<PyObject> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
    80
        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
    81
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    82
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    83
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    84
    def get(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    85
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    86
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    87
        default: Option<PyObject> = None
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    88
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    89
        let key = key.extract::<PyBytes>(py)?;
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    90
        match self
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    91
            .inner(py)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    92
            .borrow()
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    93
            .get(HgPath::new(key.data(py)))
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    94
            .map_err(|e| v2_error(py, e))?
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
    95
        {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    96
            Some(entry) => {
48059
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48046
diff changeset
    97
                Ok(Some(DirstateItem::new_as_pyobject(py, entry)?))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    98
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    99
            None => Ok(default)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   100
        }
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
49153
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   103
    def set_tracked(&self, f: PyObject) -> PyResult<PyBool> {
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   104
        let bytes = f.extract::<PyBytes>(py)?;
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   105
        let path = HgPath::new(bytes.data(py));
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   106
        let res = self.inner(py).borrow_mut().set_tracked(path);
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   107
        let was_tracked = res.or_else(|_| {
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   108
            Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   109
        })?;
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   110
        Ok(was_tracked.to_py_object(py))
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   111
    }
55c158a33fa5 dirstatemap: move `set_tracked` out of common methods and plug in Rust
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   112
49163
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   113
    def set_untracked(&self, f: PyObject) -> PyResult<PyBool> {
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   114
        let bytes = f.extract::<PyBytes>(py)?;
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   115
        let path = HgPath::new(bytes.data(py));
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   116
        let res = self.inner(py).borrow_mut().set_untracked(path);
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   117
        let was_tracked = res.or_else(|_| {
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   118
            Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   119
        })?;
119c7e2b4248 rust-dirstatemap: add `set_untracked` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49161
diff changeset
   120
        Ok(was_tracked.to_py_object(py))
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47683
diff changeset
   121
    }
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47683
diff changeset
   122
49159
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   123
    def set_clean(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
        &self,
49159
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   125
        f: PyObject,
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   126
        mode: u32,
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   127
        size: u32,
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   128
        mtime: (i64, u32, bool)
48066
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48065
diff changeset
   129
    ) -> PyResult<PyNone> {
49159
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   130
        let (mtime_s, mtime_ns, second_ambiguous) = mtime;
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   131
        let timestamp = TruncatedTimestamp::new_truncate(
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   132
            mtime_s, mtime_ns, second_ambiguous
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   133
        );
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   134
        let bytes = f.extract::<PyBytes>(py)?;
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   135
        let path = HgPath::new(bytes.data(py));
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   136
        let res = self.inner(py).borrow_mut().set_clean(
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   137
            path, mode, size, timestamp,
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   138
        );
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   139
        res.or_else(|_| {
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   140
            Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
b5c2aca84618 rust-dirstatemap: add `set_clean` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49156
diff changeset
   141
        })?;
48066
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48065
diff changeset
   142
        Ok(PyNone)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   143
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
49161
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   145
    def set_possibly_dirty(&self, f: PyObject) -> PyResult<PyNone> {
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   146
        let bytes = f.extract::<PyBytes>(py)?;
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   147
        let path = HgPath::new(bytes.data(py));
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   148
        let res = self.inner(py).borrow_mut().set_possibly_dirty(path);
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   149
        res.or_else(|_| {
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   150
            Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   151
        })?;
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   152
        Ok(PyNone)
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   153
    }
c1a3fdedc492 rust-dirstatemap: add `set_possibly_dirty` method
Raphaël Gomès <rgomes@octobus.net>
parents: 49159
diff changeset
   154
49156
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   155
    def reset_state(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   156
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   157
        f: PyObject,
49156
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   158
        wc_tracked: bool,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   159
        p1_tracked: bool,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   160
        p2_info: bool,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   161
        has_meaningful_mtime: bool,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   162
        parentfiledata: Option<(u32, u32, Option<(i64, u32, bool)>)>,
48063
76f1c76186a1 dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents: 48062
diff changeset
   163
    ) -> PyResult<PyNone> {
49156
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   164
        let mut has_meaningful_mtime = has_meaningful_mtime;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   165
        let parent_file_data = match parentfiledata {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   166
            None => {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   167
                has_meaningful_mtime = false;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   168
                None
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   169
            },
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   170
            Some(data) => {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   171
                let (mode, size, mtime_info) = data;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   172
                let mtime = if let Some(mtime_info) = mtime_info {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   173
                    let (mtime_s, mtime_ns, second_ambiguous) = mtime_info;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   174
                    let timestamp = TruncatedTimestamp::new_truncate(
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   175
                        mtime_s, mtime_ns, second_ambiguous
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   176
                    );
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   177
                    Some(timestamp)
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   178
                } else {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   179
                    has_meaningful_mtime = false;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   180
                    None
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   181
                };
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   182
                Some(ParentFileData {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   183
                    mode_size: Some((mode, size)),
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   184
                    mtime,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   185
                })
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   186
            }
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   187
        };
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   188
        let bytes = f.extract::<PyBytes>(py)?;
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   189
        let path = HgPath::new(bytes.data(py));
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   190
        let res = self.inner(py).borrow_mut().reset_state(
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   191
            path,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   192
            wc_tracked,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   193
            p1_tracked,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   194
            p2_info,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   195
            has_meaningful_mtime,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   196
            parent_file_data,
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   197
        );
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   198
        res.or_else(|_| {
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   199
            Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))
dd0430434ce9 rust-dirstatemap: add Rust implementation of `reset_state`
Raphaël Gomès <rgomes@octobus.net>
parents: 49153
diff changeset
   200
        })?;
48063
76f1c76186a1 dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents: 48062
diff changeset
   201
        Ok(PyNone)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   202
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   203
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   204
    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
   205
        let d = d.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   206
        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
   207
            .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
   208
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   209
                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
   210
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   211
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   212
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   213
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   214
    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
   215
        let d = d.extract::<PyBytes>(py)?;
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   216
        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
   217
            .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
   218
            .map_err(|e| {
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43808
diff changeset
   219
                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
   220
            })?
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   221
            .to_py_object(py))
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   222
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   223
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   224
    def write_v1(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   225
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   226
        p1: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   227
        p2: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   228
    ) -> PyResult<PyBytes> {
48462
c1b633db67fc rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents: 48440
diff changeset
   229
        let inner = self.inner(py).borrow();
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   230
        let parents = DirstateParents {
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   231
            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
   232
            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
   233
        };
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
   234
        let result = inner.pack_v1(parents);
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   235
        match result {
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   236
            Ok(packed) => Ok(PyBytes::new(py, &packed)),
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   237
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   238
                py,
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   239
                "Dirstate error".to_string(),
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   240
            )),
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   241
        }
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   242
    }
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   243
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   244
    /// Returns new data together with whether that data should be appended to
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   245
    /// the existing data file whose content is at `self.on_disk` (True),
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   246
    /// instead of written to a new data file (False).
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   247
    def write_v2(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47567
diff changeset
   248
        &self,
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   249
        can_append: bool,
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   250
    ) -> PyResult<PyObject> {
48462
c1b633db67fc rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents: 48440
diff changeset
   251
        let inner = self.inner(py).borrow();
48440
434de12918fd dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48271
diff changeset
   252
        let result = inner.pack_v2(can_append);
47291
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47138
diff changeset
   253
        match result {
48843
dd2503a63d33 rust-dirstate-v2: save proper data size if no new data on append
Raphaël Gomès <rgomes@octobus.net>
parents: 48825
diff changeset
   254
            Ok((packed, tree_metadata, append, _old_data_size)) => {
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   255
                let packed = PyBytes::new(py, &packed);
48467
2097f63575a5 rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 48462
diff changeset
   256
                let tree_metadata = PyBytes::new(py, tree_metadata.as_bytes());
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   257
                let tuple = (packed, tree_metadata, append);
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   258
                Ok(tuple.to_py_object(py).into_object())
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   259
            },
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   260
            Err(_) => Err(PyErr::new::<exc::OSError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   262
                "Dirstate error".to_string(),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   263
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   264
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   265
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   266
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   267
    def filefoldmapasdict(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   268
        let dict = PyDict::new(py);
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   269
        for item in self.inner(py).borrow_mut().iter() {
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   270
            let (path, entry) = item.map_err(|e| v2_error(py, e))?;
49190
a1fce5003ff4 rust-hg-cpython: remove use of `EntryState`
Raphaël Gomès <rgomes@octobus.net>
parents: 49179
diff changeset
   271
            if !entry.removed() {
47123
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   272
                let key = normalize_case(path);
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   273
                let value = path;
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   274
                dict.set_item(
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   275
                    py,
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   276
                    PyBytes::new(py, key.as_bytes()).into_object(),
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   277
                    PyBytes::new(py, value.as_bytes()).into_object(),
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   278
                )?;
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   279
            }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   280
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   281
        Ok(dict)
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
    def __len__(&self) -> PyResult<usize> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   285
        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
   286
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   287
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   288
    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
   289
        let key = key.extract::<PyBytes>(py)?;
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   290
        self.inner(py)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   291
            .borrow()
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   292
            .contains_key(HgPath::new(key.data(py)))
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   293
            .map_err(|e| v2_error(py, e))
42770
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
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   296
    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
   297
        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
   298
        let key = HgPath::new(key.data(py));
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   299
        match self
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   300
            .inner(py)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   301
            .borrow()
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   302
            .get(key)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   303
            .map_err(|e| v2_error(py, e))?
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   304
        {
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   305
            Some(entry) => {
48059
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48046
diff changeset
   306
                Ok(DirstateItem::new_as_pyobject(py, entry)?)
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   307
            },
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   308
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   309
                py,
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   310
                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
   311
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   312
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   314
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   315
    def keys(&self) -> PyResult<DirstateMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   316
        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
   317
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   318
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   319
            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
   320
        )
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
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   323
    def items(&self) -> PyResult<DirstateMapItemsIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   324
        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
   325
        DirstateMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   326
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   327
            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
   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
    def __iter__(&self) -> PyResult<DirstateMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   332
        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
   333
        DirstateMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   334
            py,
43285
ffc1fbd7d1f5 rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents: 43284
diff changeset
   335
            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
   336
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   337
    }
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
    // 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
   340
    def copymapcopy(&self) -> PyResult<PyDict> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   341
        let dict = PyDict::new(py);
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   342
        for item in self.inner(py).borrow().copy_map_iter() {
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   343
            let (key, value) = item.map_err(|e| v2_error(py, e))?;
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   344
            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
   345
                py,
44998
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44461
diff changeset
   346
                PyBytes::new(py, key.as_bytes()),
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44461
diff changeset
   347
                PyBytes::new(py, value.as_bytes()),
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   348
            )?;
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
        Ok(dict)
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   351
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   352
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   353
    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
   354
        let key = key.extract::<PyBytes>(py)?;
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   355
        match self
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   356
            .inner(py)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   357
            .borrow()
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   358
            .copy_map_get(HgPath::new(key.data(py)))
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   359
            .map_err(|e| v2_error(py, e))?
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   360
        {
44998
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44461
diff changeset
   361
            Some(copy) => Ok(PyBytes::new(py, copy.as_bytes())),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   362
            None => Err(PyErr::new::<exc::KeyError, _>(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   363
                py,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   364
                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
   365
            )),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   366
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   367
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   368
    def copymap(&self) -> PyResult<CopyMap> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   369
        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
   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
    def copymaplen(&self) -> PyResult<usize> {
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46891
diff changeset
   373
        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
   374
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   375
    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
   376
        let key = key.extract::<PyBytes>(py)?;
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   377
        self.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
   378
            .borrow()
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   379
            .copy_map_contains_key(HgPath::new(key.data(py)))
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   380
            .map_err(|e| v2_error(py, e))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   381
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   382
    def copymapget(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   383
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   384
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   385
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   386
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
        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
   388
        match self
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   389
            .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
   390
            .borrow()
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46891
diff changeset
   391
            .copy_map_get(HgPath::new(key.data(py)))
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   392
            .map_err(|e| v2_error(py, e))?
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   393
        {
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   394
            Some(copy) => Ok(Some(
44998
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44461
diff changeset
   395
                PyBytes::new(py, copy.as_bytes()).into_object(),
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   396
            )),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   397
            None => Ok(default),
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   398
        }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   400
    def copymapsetitem(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   401
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   402
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   403
        value: PyObject
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   404
    ) -> PyResult<PyObject> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   405
        let key = key.extract::<PyBytes>(py)?;
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   406
        let value = value.extract::<PyBytes>(py)?;
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   407
        self.inner(py)
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   408
            .borrow_mut()
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   409
            .copy_map_insert(
49179
d9a66d62c604 rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents: 49177
diff changeset
   410
                HgPath::new(key.data(py)),
d9a66d62c604 rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Raphaël Gomès <rgomes@octobus.net>
parents: 49177
diff changeset
   411
                HgPath::new(value.data(py)),
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   412
            )
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   413
            .map_err(|e| v2_error(py, e))?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   414
        Ok(py.None())
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   415
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   416
    def copymappop(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   417
        &self,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   418
        key: PyObject,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   419
        default: Option<PyObject>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   420
    ) -> PyResult<Option<PyObject>> {
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   421
        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
   422
        match self
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   423
            .inner(py)
44278
2a24ead003f0 rust-cpython: add panicking version of borrow_mut() and use it
Yuya Nishihara <yuya@tcha.org>
parents: 43874
diff changeset
   424
            .borrow_mut()
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46891
diff changeset
   425
            .copy_map_remove(HgPath::new(key.data(py)))
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   426
            .map_err(|e| v2_error(py, e))?
42960
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42896
diff changeset
   427
        {
48147
bd5f7c61d69d dirstatemap: fix copymap.pop in Rust to return the value it pops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   428
            Some(copy) => Ok(Some(
bd5f7c61d69d dirstatemap: fix copymap.pop in Rust to return the value it pops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   429
                PyBytes::new(py, copy.as_bytes()).into_object(),
bd5f7c61d69d dirstatemap: fix copymap.pop in Rust to return the value it pops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48084
diff changeset
   430
            )),
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   431
            None => Ok(default),
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
    }
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
    def copymapiter(&self) -> PyResult<CopyMapKeysIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   436
        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
   437
        CopyMapKeysIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   438
            py,
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46891
diff changeset
   439
            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
   440
        )
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   441
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   442
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   443
    def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> {
44295
281642cd1d04 rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents: 44278
diff changeset
   444
        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
   445
        CopyMapItemsIterator::from_inner(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   446
            py,
47107
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46891
diff changeset
   447
            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
   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
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   451
    def tracked_dirs(&self) -> PyResult<PyList> {
47357
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   452
        let dirs = PyList::new(py, &[]);
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   453
        for path in self.inner(py).borrow_mut().iter_tracked_dirs()
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   454
            .map_err(|e |dirstate_error(py, e))?
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   455
        {
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   456
            let path = path.map_err(|e| v2_error(py, e))?;
47357
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   457
            let path = PyBytes::new(py, path.as_bytes());
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   458
            dirs.append(py, path.into_object())
47357
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   459
        }
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   460
        Ok(dirs)
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   461
    }
3b9914b28133 dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents: 47343
diff changeset
   462
49175
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   463
    def setparents_fixup(&self) -> PyResult<PyDict> {
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   464
        let dict = PyDict::new(py);
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   465
        let copies = self.inner(py).borrow_mut().setparents_fixup();
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   466
        for (key, value) in copies.map_err(|e| v2_error(py, e))? {
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   467
            dict.set_item(
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   468
                py,
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   469
                PyBytes::new(py, key.as_bytes()),
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   470
                PyBytes::new(py, value.as_bytes()),
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   471
            )?;
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   472
        }
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   473
        Ok(dict)
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   474
    }
3df46f3a3d6c rust-dirstatemap: implement part of the `setparents` logic
Raphaël Gomès <rgomes@octobus.net>
parents: 49167
diff changeset
   475
48045
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   476
    def debug_iter(&self, all: bool) -> PyResult<PyList> {
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   477
        let dirs = PyList::new(py, &[]);
48045
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   478
        for item in self.inner(py).borrow().debug_iter(all) {
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   479
            let (path, (state, mode, size, mtime)) =
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   480
                item.map_err(|e| v2_error(py, e))?;
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   481
            let path = PyBytes::new(py, path.as_bytes());
48046
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
   482
            let item = (path, state, mode, size, mtime);
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
   483
            dirs.append(py, item.to_py_object(py).into_object())
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   484
        }
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   485
        Ok(dirs)
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   486
    }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   487
});
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   488
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   489
impl DirstateMap {
47126
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47123
diff changeset
   490
    pub fn get_inner_mut<'a>(
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   491
        &'a self,
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   492
        py: Python<'a>,
48084
3d0a9c6e614d dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents: 48083
diff changeset
   493
    ) -> RefMut<'a, OwningDirstateMap> {
47126
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47123
diff changeset
   494
        self.inner(py).borrow_mut()
43273
478d0b1bf0c5 rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents: 43208
diff changeset
   495
    }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   496
    fn translate_key(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   497
        py: Python,
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   498
        res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   499
    ) -> PyResult<Option<PyBytes>> {
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   500
        let (f, _entry) = res.map_err(|e| v2_error(py, e))?;
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   501
        Ok(Some(PyBytes::new(py, f.as_bytes())))
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   502
    }
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   503
    fn translate_key_value(
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   504
        py: Python,
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   505
        res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   506
    ) -> PyResult<Option<(PyBytes, PyObject)>> {
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   507
        let (f, entry) = res.map_err(|e| v2_error(py, e))?;
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   508
        Ok(Some((
44998
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44461
diff changeset
   509
            PyBytes::new(py, f.as_bytes()),
48059
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48046
diff changeset
   510
            DirstateItem::new_as_pyobject(py, entry)?,
45613
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 44998
diff changeset
   511
        )))
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 44998
diff changeset
   512
    }
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   513
}
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   514
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   515
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   516
    DirstateMapKeysIterator,
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
   517
    UnsafePyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   518
    DirstateMap::translate_key,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   519
    Option<PyBytes>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   520
);
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   521
42895
ea91a126c803 rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents: 42894
diff changeset
   522
py_shared_iterator!(
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   523
    DirstateMapItemsIterator,
44296
bad4e7b361d2 rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents: 44295
diff changeset
   524
    UnsafePyLeaked<StateMapIter<'static>>,
42770
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   525
    DirstateMap::translate_key_value,
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   526
    Option<(PyBytes, PyObject)>
4e8f504424f3 rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   527
);
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   528
46634
98a455a62699 rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents: 46508
diff changeset
   529
fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<Node> {
42816
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   530
    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
   531
    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
   532
        Ok(s) => Ok(s),
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   533
        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
   534
    }
79561843729a rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents: 42815
diff changeset
   535
}
47343
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   536
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   537
pub(super) fn v2_error(py: Python<'_>, _: DirstateV2ParseError) -> PyErr {
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   538
    PyErr::new::<exc::ValueError, _>(py, "corrupted dirstate-v2")
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47340
diff changeset
   539
}
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   540
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   541
fn dirstate_error(py: Python<'_>, e: DirstateError) -> PyErr {
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   542
    PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e))
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   543
}