author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sat, 02 Oct 2021 00:44:17 +0200 | |
changeset 48147 | bd5f7c61d69d |
parent 48084 | 3d0a9c6e614d |
child 48271 | 269ff8978086 |
permissions | -rw-r--r-- |
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 |
use std::convert::TryInto; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
use cpython::{ |
48071
cd13d3c2ad2e
dirstate: drop the `clearambiguoustimes` method for the map
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48066
diff
changeset
|
15 |
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
|
16 |
PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
}; |
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}, |
48059
d5528ac9b4f2
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
48046
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::{ |
47115
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
25 |
dirstate::parsers::Timestamp, |
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
26 |
dirstate::StateMapIter, |
47982
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
27 |
dirstate_tree::dirstate_map::DirstateMap as TreeDirstateMap, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
28 |
dirstate_tree::on_disk::DirstateV2ParseError, |
47982
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
29 |
dirstate_tree::owning::OwningDirstateMap, |
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
30 |
revlog::Node, |
47123
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
31 |
utils::files::normalize_case, |
42960
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42896
diff
changeset
|
32 |
utils::hg_path::{HgPath, HgPathBuf}, |
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
33 |
DirstateEntry, DirstateError, DirstateParents, EntryState, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
}; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
// TODO |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
// 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
|
38 |
// 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
|
39 |
// 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
|
40 |
// 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
|
41 |
// every method in `CopyMap` (copymapcopy, etc.). |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
// 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
|
43 |
// 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
|
44 |
// `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
|
45 |
// `RustDirstateMap`, rightfully so. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
// 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
|
47 |
// 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
|
48 |
py_class!(pub class DirstateMap |py| { |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
49 |
@shared data inner: OwningDirstateMap; |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
|
47136
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
51 |
/// 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
|
52 |
@staticmethod |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
) -> PyResult<PyObject> { |
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
56 |
let on_disk = PyBytesDeref::new(py, on_disk); |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
57 |
let mut map = OwningDirstateMap::new_empty(on_disk); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
58 |
let (on_disk, map_placeholder) = map.get_pair_mut(); |
47982
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
59 |
|
48083
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
60 |
let (actual_map, parents) = TreeDirstateMap::new_v1(on_disk) |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
61 |
.map_err(|e| dirstate_error(py, e))?; |
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48076
diff
changeset
|
62 |
*map_placeholder = actual_map; |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
63 |
let map = Self::create_instance(py, map)?; |
48042
1194394510ba
rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents:
47982
diff
changeset
|
64 |
let parents = parents.map(|p| { |
1194394510ba
rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents:
47982
diff
changeset
|
65 |
let p1 = PyBytes::new(py, p.p1.as_bytes()); |
1194394510ba
rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents:
47982
diff
changeset
|
66 |
let p2 = PyBytes::new(py, p.p2.as_bytes()); |
1194394510ba
rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents:
47982
diff
changeset
|
67 |
(p1, p2) |
1194394510ba
rust: Remove the `rustext.parsers` module
Simon Sapin <simon.sapin@octobus.net>
parents:
47982
diff
changeset
|
68 |
}); |
47136
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47135
diff
changeset
|
69 |
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
|
70 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
|
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
72 |
/// Returns a DirstateMap |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
73 |
@staticmethod |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
74 |
def new_v2( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
tree_metadata: PyBytes, |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
78 |
) -> PyResult<PyObject> { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
79 |
let dirstate_error = |e: DirstateError| { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
80 |
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
|
81 |
}; |
47982
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
82 |
let on_disk = PyBytesDeref::new(py, on_disk); |
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
83 |
let mut map = OwningDirstateMap::new_empty(on_disk); |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
84 |
let (on_disk, map_placeholder) = map.get_pair_mut(); |
47982
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
85 |
*map_placeholder = TreeDirstateMap::new_v2( |
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
86 |
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
|
87 |
).map_err(dirstate_error)?; |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
88 |
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
|
89 |
Ok(map.into_object()) |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
90 |
} |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
91 |
|
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
def clear(&self) -> PyResult<PyObject> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
93 |
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
|
94 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
def get( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
default: Option<PyObject> = None |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
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
|
103 |
match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
104 |
.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
105 |
.borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
106 |
.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
|
107 |
.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
|
108 |
{ |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
None => Ok(default) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
|
48060
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48059
diff
changeset
|
116 |
def set_dirstate_item( |
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48059
diff
changeset
|
117 |
&self, |
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48059
diff
changeset
|
118 |
path: PyObject, |
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48059
diff
changeset
|
119 |
item: DirstateItem |
32ef647821b2
dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents:
48059
diff
changeset
|
120 |
) -> PyResult<PyObject> { |
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 |
let f = path.extract::<PyBytes>(py)?; |
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 |
let filename = HgPath::new(f.data(py)); |
48062
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48060
diff
changeset
|
123 |
self.inner(py) |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48060
diff
changeset
|
124 |
.borrow_mut() |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48060
diff
changeset
|
125 |
.set_entry(filename, item.get_entry(py)) |
9b2a51b2c36a
dirstate: Propagate dirstate-v2 parse errors from set_dirstate_item
Simon Sapin <simon.sapin@octobus.net>
parents:
48060
diff
changeset
|
126 |
.map_err(|e| v2_error(py, e))?; |
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
|
127 |
Ok(py.None()) |
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
|
128 |
} |
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
|
129 |
|
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
def addfile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
&self, |
48066
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
132 |
f: PyBytes, |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
133 |
item: DirstateItem, |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
134 |
) -> PyResult<PyNone> { |
47518
f6f25ab6bfc8
rust-dirstatemap: expand the wrapping code a bit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
135 |
let filename = HgPath::new(f.data(py)); |
48066
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
136 |
let entry = item.get_entry(py); |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
137 |
self.inner(py) |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
138 |
.borrow_mut() |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
139 |
.add_file(filename, entry) |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
140 |
.map_err(|e |dirstate_error(py, e))?; |
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48065
diff
changeset
|
141 |
Ok(PyNone) |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
} |
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 |
def removefile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
f: PyObject, |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47482
diff
changeset
|
147 |
in_merge: PyObject |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 |
) -> PyResult<PyObject> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
149 |
self.inner(py).borrow_mut() |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
.remove_file( |
42960
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42896
diff
changeset
|
151 |
HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47482
diff
changeset
|
152 |
in_merge.extract::<PyBool>(py)?.is_true(), |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 |
.or_else(|_| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 |
Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
156 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
157 |
"Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
158 |
)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
159 |
})?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
161 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
162 |
|
48065
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
163 |
def drop_item_and_copy_source( |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 |
&self, |
48063
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
165 |
f: PyBytes, |
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
166 |
) -> PyResult<PyNone> { |
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
167 |
self.inner(py) |
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
168 |
.borrow_mut() |
48065
2ac0e6b23222
dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents:
48063
diff
changeset
|
169 |
.drop_entry_and_copy_source(HgPath::new(f.data(py))) |
48063
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
170 |
.map_err(|e |dirstate_error(py, e))?; |
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48062
diff
changeset
|
171 |
Ok(PyNone) |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
172 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 |
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
|
175 |
let d = d.extract::<PyBytes>(py)?; |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
176 |
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
|
177 |
.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
|
178 |
.map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43808
diff
changeset
|
179 |
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
|
180 |
})? |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 |
.to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 |
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
|
185 |
let d = d.extract::<PyBytes>(py)?; |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
186 |
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
|
187 |
.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
|
188 |
.map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43808
diff
changeset
|
189 |
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
|
190 |
})? |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
.to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 |
|
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
194 |
def write_v1( |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 |
p1: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 |
p2: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 |
now: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
) -> PyResult<PyBytes> { |
47115
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
200 |
let now = Timestamp(now.extract(py)?); |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
201 |
|
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
202 |
let mut inner = self.inner(py).borrow_mut(); |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 |
let parents = DirstateParents { |
42816
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42815
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
}; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
207 |
let result = inner.pack_v1(parents, now); |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
208 |
match result { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
209 |
Ok(packed) => Ok(PyBytes::new(py, &packed)), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
210 |
Err(_) => Err(PyErr::new::<exc::OSError, _>( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
211 |
py, |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
212 |
"Dirstate error".to_string(), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
213 |
)), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
214 |
} |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
215 |
} |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
216 |
|
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
217 |
/// 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
|
218 |
/// 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
|
219 |
/// 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
|
220 |
def write_v2( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
221 |
&self, |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
222 |
now: PyObject, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
223 |
can_append: bool, |
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
224 |
) -> PyResult<PyObject> { |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
225 |
let now = Timestamp(now.extract(py)?); |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
|
47291
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47138
diff
changeset
|
227 |
let mut inner = self.inner(py).borrow_mut(); |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
228 |
let result = inner.pack_v2(now, 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
|
229 |
match result { |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
230 |
Ok((packed, tree_metadata, append)) => { |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
231 |
let packed = PyBytes::new(py, &packed); |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
232 |
let tree_metadata = PyBytes::new(py, &tree_metadata); |
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
}, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
Err(_) => Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
"Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
def filefoldmapasdict(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
let (path, entry) = item.map_err(|e| v2_error(py, e))?; |
48044
f2a9db29cb2d
rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents:
48042
diff
changeset
|
247 |
if entry.state() != EntryState::Removed { |
47123
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
248 |
let key = normalize_case(path); |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
249 |
let value = path; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
250 |
dict.set_item( |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
251 |
py, |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
)?; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47115
diff
changeset
|
255 |
} |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
Ok(dict) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
def __len__(&self) -> PyResult<usize> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
261 |
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
|
262 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 |
def __contains__(&self, key: PyObject) -> PyResult<bool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 |
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
|
266 |
self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
267 |
.borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
268 |
.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
|
269 |
.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
|
270 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
276 |
.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
277 |
.borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
278 |
.get(key) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
279 |
.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
|
280 |
{ |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 |
None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
py, |
42960
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42896
diff
changeset
|
286 |
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
|
287 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 |
def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
292 |
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
|
293 |
DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 |
py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
295 |
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
|
296 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 |
def items(&self) -> PyResult<DirstateMapItemsIterator> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
300 |
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
|
301 |
DirstateMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 |
py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
303 |
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
|
304 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 |
def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
308 |
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
|
309 |
DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 |
py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
311 |
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
|
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 |
// 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
|
316 |
def copymapcopy(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
py, |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44461
diff
changeset
|
322 |
PyBytes::new(py, key.as_bytes()), |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44461
diff
changeset
|
323 |
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
|
324 |
)?; |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 |
Ok(dict) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 |
} |
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 |
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
|
330 |
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
|
331 |
match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
332 |
.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
333 |
.borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
334 |
.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
|
335 |
.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
|
336 |
{ |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44461
diff
changeset
|
337 |
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
|
338 |
None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
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
|
341 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 |
def copymap(&self) -> PyResult<CopyMap> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
345 |
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
|
346 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
347 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 |
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
|
349 |
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
|
350 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
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
|
354 |
.borrow() |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
355 |
.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
|
356 |
.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
|
357 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 |
def copymapget( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 |
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
|
364 |
match self |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
365 |
.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
|
366 |
.borrow() |
47107
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
367 |
.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
|
368 |
.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
|
369 |
{ |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42896
diff
changeset
|
370 |
Some(copy) => Ok(Some( |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44461
diff
changeset
|
371 |
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
|
372 |
)), |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
375 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
376 |
def copymapsetitem( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
value: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
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
|
383 |
self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
384 |
.borrow_mut() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
385 |
.copy_map_insert( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
386 |
HgPathBuf::from_bytes(key.data(py)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
387 |
HgPathBuf::from_bytes(value.data(py)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
388 |
) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
389 |
.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
|
390 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
def copymappop( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 |
default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 |
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
|
398 |
match self |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
399 |
.inner(py) |
44278
2a24ead003f0
rust-cpython: add panicking version of borrow_mut() and use it
Yuya Nishihara <yuya@tcha.org>
parents:
43874
diff
changeset
|
400 |
.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
|
401 |
.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
|
402 |
.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
|
403 |
{ |
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
|
404 |
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
|
405 |
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
|
406 |
)), |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 |
None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
412 |
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
|
413 |
CopyMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
414 |
py, |
47107
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
415 |
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
|
416 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
419 |
def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
44295
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44278
diff
changeset
|
420 |
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
|
421 |
CopyMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 |
py, |
47107
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
423 |
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
|
424 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
425 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 |
|
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
.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
|
431 |
{ |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
} |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
436 |
Ok(dirs) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
437 |
} |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
438 |
|
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
439 |
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
|
440 |
let dirs = PyList::new(py, &[]); |
48045
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48044
diff
changeset
|
441 |
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
|
442 |
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
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
} |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
448 |
Ok(dirs) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
449 |
} |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
450 |
}); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
451 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 |
impl DirstateMap { |
47126
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47123
diff
changeset
|
453 |
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
|
454 |
&'a self, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43208
diff
changeset
|
455 |
py: Python<'a>, |
48084
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48083
diff
changeset
|
456 |
) -> 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
|
457 |
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
|
458 |
} |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 |
fn translate_key( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 |
py: Python, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
461 |
res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
462 |
) -> PyResult<Option<PyBytes>> { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
463 |
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
|
464 |
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
|
465 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
466 |
fn translate_key_value( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
467 |
py: Python, |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
468 |
res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
469 |
) -> PyResult<Option<(PyBytes, PyObject)>> { |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
470 |
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
|
471 |
Ok(Some(( |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44461
diff
changeset
|
472 |
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
|
473 |
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
|
474 |
))) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44998
diff
changeset
|
475 |
} |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
476 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
477 |
|
42895
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42894
diff
changeset
|
478 |
py_shared_iterator!( |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
479 |
DirstateMapKeysIterator, |
44296
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44295
diff
changeset
|
480 |
UnsafePyLeaked<StateMapIter<'static>>, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
481 |
DirstateMap::translate_key, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
482 |
Option<PyBytes> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
483 |
); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
484 |
|
42895
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42894
diff
changeset
|
485 |
py_shared_iterator!( |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
486 |
DirstateMapItemsIterator, |
44296
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44295
diff
changeset
|
487 |
UnsafePyLeaked<StateMapIter<'static>>, |
42770
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
488 |
DirstateMap::translate_key_value, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
489 |
Option<(PyBytes, PyObject)> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
490 |
); |
42816
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42815
diff
changeset
|
491 |
|
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
Ok(s) => Ok(s), |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42815
diff
changeset
|
496 |
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
|
497 |
} |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42815
diff
changeset
|
498 |
} |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
499 |
|
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
} |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
503 |
|
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
504 |
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
|
505 |
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
|
506 |
} |