Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/dirstate/dirstate_map.rs @ 53042:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 15011324a80b |
children |
rev | line source |
---|---|
42754
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 |
52410
15011324a80b
rust: made the crate of hg-cpython importable
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52301
diff
changeset
|
11 use std::cell::RefMut; |
42754
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::{ |
48056
cd13d3c2ad2e
dirstate: drop the `clearambiguoustimes` method for the map
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48051
diff
changeset
|
14 exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject, |
48061
060cd909439f
dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
15 PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
16 }; |
52301
79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52299
diff
changeset
|
17 use hg::dirstate::{ |
79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52299
diff
changeset
|
18 dirstate_map::{ |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
19 DirstateEntryReset, DirstateIdentity as CoreDirstateIdentity, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
20 }, |
52301
79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52299
diff
changeset
|
21 entry::{DirstateEntry, ParentFileData, TruncatedTimestamp}, |
79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52299
diff
changeset
|
22 DirstateError, |
52040
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
23 }; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 use crate::{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
48392
434de12918fd
dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48260
diff
changeset
|
27 dirstate::item::DirstateItem, |
47954
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
28 pybytes_deref::PyBytesDeref, |
42754
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 use hg::{ |
52298
db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52050
diff
changeset
|
31 dirstate::dirstate_map::DirstateMapWriteMode, |
db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52050
diff
changeset
|
32 dirstate::on_disk::DirstateV2ParseError, |
db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52050
diff
changeset
|
33 dirstate::owning::OwningDirstateMap, dirstate::StateMapIter, revlog::Node, |
52301
79e8118cd846
rust-lib: move `Dirstate*Error` to the `dirstate` module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52299
diff
changeset
|
34 utils::files::normalize_case, utils::hg_path::HgPath, DirstateParents, |
42754
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 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
37 // TODO |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
38 // 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
|
39 // 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
|
40 // 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
|
41 // 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
|
42 // every method in `CopyMap` (copymapcopy, etc.). |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
43 // 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
|
44 // 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
|
45 // `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
|
46 // `RustDirstateMap`, rightfully so. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 // 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
|
48 // 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
|
49 py_class!(pub class DirstateMap |py| { |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
50 @shared data inner: OwningDirstateMap; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
52 /// Returns a `(dirstate_map, parents)` tuple |
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
53 @staticmethod |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
54 def new_v1( |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
55 on_disk: PyBytes, |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
56 identity: Option<DirstateIdentity>, |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
57 ) -> PyResult<PyObject> { |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
58 let on_disk = PyBytesDeref::new(py, on_disk); |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
59 let (map, parents) = OwningDirstateMap::new_v1( |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
60 on_disk, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
61 identity.map(|i| *i.inner(py)) |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
62 ) |
48068
bf8837e3d7ce
dirstate: Remove the flat Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
48061
diff
changeset
|
63 .map_err(|e| dirstate_error(py, e))?; |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
64 let map = Self::create_instance(py, map)?; |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48421
diff
changeset
|
65 let p1 = PyBytes::new(py, parents.p1.as_bytes()); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48421
diff
changeset
|
66 let p2 = PyBytes::new(py, parents.p2.as_bytes()); |
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48421
diff
changeset
|
67 let parents = (p1, p2); |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
68 Ok((map, parents).to_py_object(py).into_object()) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
71 /// Returns a DirstateMap |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
72 @staticmethod |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
73 def new_v2( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
74 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
|
75 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
|
76 tree_metadata: PyBytes, |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
77 uuid: PyBytes, |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
78 identity: Option<DirstateIdentity>, |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
79 ) -> PyResult<PyObject> { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
80 let dirstate_error = |e: DirstateError| { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
81 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
|
82 }; |
47954
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47692
diff
changeset
|
83 let on_disk = PyBytesDeref::new(py, on_disk); |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
84 let uuid = uuid.data(py); |
49000
dd6b67d5c256
rust: fix unsound `OwningDirstateMap`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48421
diff
changeset
|
85 let map = OwningDirstateMap::new_v2( |
50245
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50243
diff
changeset
|
86 on_disk, |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50243
diff
changeset
|
87 data_size, |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50243
diff
changeset
|
88 tree_metadata.data(py), |
dbe09fb038fc
rhg: remember the inode of .hg/dirstate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50243
diff
changeset
|
89 uuid.to_owned(), |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
90 identity.map(|i| *i.inner(py)), |
47682
78f7f0d490ee
dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47678
diff
changeset
|
91 ).map_err(dirstate_error)?; |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
92 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
|
93 Ok(map.into_object()) |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
94 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
95 |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
96 /// Returns an empty DirstateMap. Only used for a new dirstate. |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
97 @staticmethod |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
98 def new_empty() -> PyResult<PyObject> { |
52029
88aa21d654e5
rust-dirstate: actually remember the identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51615
diff
changeset
|
99 let map = OwningDirstateMap::new_empty(vec![], None); |
50243
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
100 let map = Self::create_instance(py, map)?; |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
101 Ok(map.into_object()) |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
102 } |
6cce0afc1454
rust-dirstate: remember the data file uuid dirstate was loaded with
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50222
diff
changeset
|
103 |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 def clear(&self) -> PyResult<PyObject> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
105 self.inner(py).borrow_mut().clear(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
106 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
107 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
108 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
109 def get( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
110 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
111 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
112 default: Option<PyObject> = None |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
113 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
114 let key = key.extract::<PyBytes>(py)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
115 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
116 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
117 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
118 .get(HgPath::new(key.data(py))) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
119 .map_err(|e| v2_error(py, e))? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
120 { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
121 Some(entry) => { |
48044
d5528ac9b4f2
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
48024
diff
changeset
|
122 Ok(Some(DirstateItem::new_as_pyobject(py, entry)?)) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
123 }, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
124 None => Ok(default) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
125 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
126 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
49098
55c158a33fa5
dirstatemap: move `set_tracked` out of common methods and plug in Rust
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49000
diff
changeset
|
128 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:
49000
diff
changeset
|
129 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:
49000
diff
changeset
|
130 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:
49000
diff
changeset
|
131 let res = self.inner(py).borrow_mut().set_tracked(path); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49631
diff
changeset
|
132 let was_tracked = res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?; |
49098
55c158a33fa5
dirstatemap: move `set_tracked` out of common methods and plug in Rust
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49000
diff
changeset
|
133 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:
49000
diff
changeset
|
134 } |
55c158a33fa5
dirstatemap: move `set_tracked` out of common methods and plug in Rust
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49000
diff
changeset
|
135 |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49106
diff
changeset
|
136 def set_untracked(&self, f: PyObject) -> PyResult<PyBool> { |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49106
diff
changeset
|
137 let bytes = f.extract::<PyBytes>(py)?; |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49106
diff
changeset
|
138 let path = HgPath::new(bytes.data(py)); |
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49106
diff
changeset
|
139 let res = self.inner(py).borrow_mut().set_untracked(path); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49631
diff
changeset
|
140 let was_tracked = res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?; |
49108
119c7e2b4248
rust-dirstatemap: add `set_untracked` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49106
diff
changeset
|
141 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
|
142 } |
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
|
143 |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
144 def set_clean( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
145 &self, |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
146 f: PyObject, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
147 mode: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
148 size: u32, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
149 mtime: (i64, u32, bool) |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48050
diff
changeset
|
150 ) -> PyResult<PyNone> { |
49104
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
151 let (mtime_s, mtime_ns, second_ambiguous) = mtime; |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
152 let timestamp = TruncatedTimestamp::new_truncate( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
153 mtime_s, mtime_ns, second_ambiguous |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
154 ); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
155 let bytes = f.extract::<PyBytes>(py)?; |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
156 let path = HgPath::new(bytes.data(py)); |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
157 let res = self.inner(py).borrow_mut().set_clean( |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
158 path, mode, size, timestamp, |
b5c2aca84618
rust-dirstatemap: add `set_clean` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49101
diff
changeset
|
159 ); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49631
diff
changeset
|
160 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?; |
48051
98c0408324e6
dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents:
48050
diff
changeset
|
161 Ok(PyNone) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
162 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
163 |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
164 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:
49104
diff
changeset
|
165 let bytes = f.extract::<PyBytes>(py)?; |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
166 let path = HgPath::new(bytes.data(py)); |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
167 let res = self.inner(py).borrow_mut().set_possibly_dirty(path); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49631
diff
changeset
|
168 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?; |
49106
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
169 Ok(PyNone) |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
170 } |
c1a3fdedc492
rust-dirstatemap: add `set_possibly_dirty` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49104
diff
changeset
|
171 |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
172 def reset_state( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
173 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
174 f: PyObject, |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
175 wc_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
176 p1_tracked: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
177 p2_info: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
178 has_meaningful_mtime: bool, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
179 parentfiledata: Option<(u32, u32, Option<(i64, u32, bool)>)>, |
48048
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48047
diff
changeset
|
180 ) -> PyResult<PyNone> { |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
181 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:
49098
diff
changeset
|
182 let parent_file_data = match parentfiledata { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
183 None => { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
184 has_meaningful_mtime = false; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
185 None |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
186 }, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
187 Some(data) => { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
188 let (mode, size, mtime_info) = data; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
189 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:
49098
diff
changeset
|
190 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:
49098
diff
changeset
|
191 let timestamp = TruncatedTimestamp::new_truncate( |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
192 mtime_s, mtime_ns, second_ambiguous |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
193 ); |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
194 Some(timestamp) |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
195 } else { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
196 has_meaningful_mtime = false; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
197 None |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
198 }; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
199 Some(ParentFileData { |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
200 mode_size: Some((mode, size)), |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
201 mtime, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
202 }) |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
203 } |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
204 }; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
205 let bytes = f.extract::<PyBytes>(py)?; |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
206 let path = HgPath::new(bytes.data(py)); |
52040
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
207 let reset = DirstateEntryReset { |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
208 filename: path, |
49101
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
209 wc_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
210 p1_tracked, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
211 p2_info, |
dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49098
diff
changeset
|
212 has_meaningful_mtime, |
52040
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
213 parent_file_data_opt: parent_file_data, |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
214 from_empty: false |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
215 }; |
0cd16b1d613f
rust-dirstate: use a struct as arguments for the high-level `reset_state`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52029
diff
changeset
|
216 let res = self.inner(py).borrow_mut().reset_state(reset); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49631
diff
changeset
|
217 res.map_err(|_| PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()))?; |
48048
76f1c76186a1
dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents:
48047
diff
changeset
|
218 Ok(PyNone) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
219 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
220 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
221 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
|
222 let d = d.extract::<PyBytes>(py)?; |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
223 Ok(self.inner(py).borrow_mut() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
224 .has_tracked_dir(HgPath::new(d.data(py))) |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
225 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
226 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
227 })? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
228 .to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
229 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
230 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
231 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
|
232 let d = d.extract::<PyBytes>(py)?; |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
233 Ok(self.inner(py).borrow_mut() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
234 .has_dir(HgPath::new(d.data(py))) |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
235 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
236 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43788
diff
changeset
|
237 })? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
238 .to_py_object(py)) |
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 |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
241 def write_v1( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
242 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
243 p1: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
244 p2: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
245 ) -> PyResult<PyBytes> { |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
246 let inner = self.inner(py).borrow(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
247 let parents = DirstateParents { |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
248 p1: extract_node_id(py, &p1)?, |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
249 p2: extract_node_id(py, &p2)?, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
250 }; |
48392
434de12918fd
dirstate: remove need_delay logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48260
diff
changeset
|
251 let result = inner.pack_v1(parents); |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
252 match result { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
253 Ok(packed) => Ok(PyBytes::new(py, &packed)), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
254 Err(_) => Err(PyErr::new::<exc::OSError, _>( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
255 py, |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
256 "Dirstate error".to_string(), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
257 )), |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
258 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
259 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
260 |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
261 /// 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
|
262 /// 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
|
263 /// 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
|
264 def write_v2( |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47567
diff
changeset
|
265 &self, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
266 write_mode: usize, |
47678
065e61628980
dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents:
47675
diff
changeset
|
267 ) -> PyResult<PyObject> { |
48416
c1b633db67fc
rust: Serializing a DirstateMap does not mutate it anymore
Simon Sapin <simon.sapin@octobus.net>
parents:
48392
diff
changeset
|
268 let inner = self.inner(py).borrow(); |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
269 let rust_write_mode = match write_mode { |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
270 0 => DirstateMapWriteMode::Auto, |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
271 1 => DirstateMapWriteMode::ForceNewDataFile, |
50222
ecd28d89c29e
dirstate-v2: add devel config option to control write behavior
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50221
diff
changeset
|
272 2 => DirstateMapWriteMode::ForceAppend, |
50221
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
273 _ => DirstateMapWriteMode::Auto, // XXX should we error out? |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
274 }; |
1891086f6c7f
dirstate: use more than a bool to control append behavior
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49147
diff
changeset
|
275 let result = inner.pack_v2(rust_write_mode); |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
276 match result { |
49145
dd2503a63d33
rust-dirstate-v2: save proper data size if no new data on append
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49000
diff
changeset
|
277 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
|
278 let packed = PyBytes::new(py, &packed); |
48421
2097f63575a5
rhg: Add Repo::write_dirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
48416
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 }, |
51615
ccf5c44092db
rust-cpython: don't swallow the dirstate error message
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50252
diff
changeset
|
283 Err(e) => Err(PyErr::new::<exc::OSError, _>( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
284 py, |
51615
ccf5c44092db
rust-cpython: don't swallow the dirstate error message
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50252
diff
changeset
|
285 e.to_string(), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
286 )), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
287 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
288 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
290 def filefoldmapasdict(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
291 let dict = PyDict::new(py); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
292 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:
47332
diff
changeset
|
293 let (path, entry) = item.map_err(|e| v2_error(py, e))?; |
49135
a1fce5003ff4
rust-hg-cpython: remove use of `EntryState`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49124
diff
changeset
|
294 if !entry.removed() { |
47109
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
295 let key = normalize_case(path); |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
296 let value = path; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
297 dict.set_item( |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
298 py, |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
299 PyBytes::new(py, key.as_bytes()).into_object(), |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
300 PyBytes::new(py, value.as_bytes()).into_object(), |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
301 )?; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
302 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
303 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
304 Ok(dict) |
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 __len__(&self) -> PyResult<usize> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
308 Ok(self.inner(py).borrow().len()) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
309 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
310 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
311 def __contains__(&self, key: PyObject) -> PyResult<bool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
312 let key = key.extract::<PyBytes>(py)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
313 self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
314 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
315 .contains_key(HgPath::new(key.data(py))) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
316 .map_err(|e| v2_error(py, e)) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
317 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
319 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
|
320 let key = key.extract::<PyBytes>(py)?; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
321 let key = HgPath::new(key.data(py)); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
322 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
323 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
324 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
325 .get(key) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
326 .map_err(|e| v2_error(py, e))? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
327 { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
328 Some(entry) => { |
48044
d5528ac9b4f2
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
48024
diff
changeset
|
329 Ok(DirstateItem::new_as_pyobject(py, entry)?) |
42754
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 None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
332 py, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
333 String::from_utf8_lossy(key.as_bytes()), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
334 )), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
335 } |
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 def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
339 let leaked_ref = self.inner(py).leak_immutable(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
340 DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
341 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
342 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
343 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
344 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
345 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
346 def items(&self) -> PyResult<DirstateMapItemsIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
347 let leaked_ref = self.inner(py).leak_immutable(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
348 DirstateMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
349 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
350 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
42754
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 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
354 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
355 let leaked_ref = self.inner(py).leak_immutable(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
356 DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
357 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
358 unsafe { leaked_ref.map(py, |o| o.iter()) }, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
359 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
360 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
362 // 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
|
363 def copymapcopy(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
364 let dict = PyDict::new(py); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
365 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:
47332
diff
changeset
|
366 let (key, value) = item.map_err(|e| v2_error(py, e))?; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
367 dict.set_item( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
368 py, |
44973
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44441
diff
changeset
|
369 PyBytes::new(py, key.as_bytes()), |
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44441
diff
changeset
|
370 PyBytes::new(py, value.as_bytes()), |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
371 )?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
372 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
373 Ok(dict) |
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 copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
377 let key = key.extract::<PyBytes>(py)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
378 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
379 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
380 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
381 .copy_map_get(HgPath::new(key.data(py))) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
382 .map_err(|e| v2_error(py, e))? |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
383 { |
44973
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44441
diff
changeset
|
384 Some(copy) => Ok(PyBytes::new(py, copy.as_bytes())), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
385 None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
386 py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
387 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
|
388 )), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
389 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
390 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
391 def copymap(&self) -> PyResult<CopyMap> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
392 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
|
393 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
394 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
395 def copymaplen(&self) -> PyResult<usize> { |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
396 Ok(self.inner(py).borrow().copy_map_len()) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
397 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
398 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
|
399 let key = key.extract::<PyBytes>(py)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
400 self.inner(py) |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
401 .borrow() |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
402 .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:
47332
diff
changeset
|
403 .map_err(|e| v2_error(py, e)) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
404 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
405 def copymapget( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
406 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
407 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
408 default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
409 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
410 let key = key.extract::<PyBytes>(py)?; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
411 match self |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
412 .inner(py) |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
413 .borrow() |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
414 .copy_map_get(HgPath::new(key.data(py))) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
415 .map_err(|e| v2_error(py, e))? |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
416 { |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
417 Some(copy) => Ok(Some( |
44973
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44441
diff
changeset
|
418 PyBytes::new(py, copy.as_bytes()).into_object(), |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
419 )), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
420 None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
421 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
422 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
423 def copymapsetitem( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
424 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
425 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
426 value: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
427 ) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
428 let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
429 let value = value.extract::<PyBytes>(py)?; |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
430 self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
431 .borrow_mut() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
432 .copy_map_insert( |
49124
d9a66d62c604
rust-dirstatemap: use `&HgPath` instead of `HgPathBuf` in `copy_map_insert`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49122
diff
changeset
|
433 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:
49122
diff
changeset
|
434 HgPath::new(value.data(py)), |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
435 ) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
436 .map_err(|e| v2_error(py, e))?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
437 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
438 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
439 def copymappop( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
440 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
441 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
442 default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
443 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
444 let key = key.extract::<PyBytes>(py)?; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
445 match self |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
446 .inner(py) |
44203
2a24ead003f0
rust-cpython: add panicking version of borrow_mut() and use it
Yuya Nishihara <yuya@tcha.org>
parents:
43863
diff
changeset
|
447 .borrow_mut() |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
448 .copy_map_remove(HgPath::new(key.data(py))) |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
449 .map_err(|e| v2_error(py, e))? |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42890
diff
changeset
|
450 { |
48135
bd5f7c61d69d
dirstatemap: fix copymap.pop in Rust to return the value it pops
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48069
diff
changeset
|
451 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:
48069
diff
changeset
|
452 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:
48069
diff
changeset
|
453 )), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
454 None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
455 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
456 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
457 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
458 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
459 let leaked_ref = self.inner(py).leak_immutable(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
460 CopyMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
461 py, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
462 unsafe { leaked_ref.map(py, |o| o.copy_map_iter()) }, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
463 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
464 } |
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 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
467 let leaked_ref = self.inner(py).leak_immutable(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
468 CopyMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
469 py, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
470 unsafe { leaked_ref.map(py, |o| o.copy_map_iter()) }, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
471 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
472 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
473 |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
474 def tracked_dirs(&self) -> PyResult<PyList> { |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
475 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
|
476 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
|
477 .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
|
478 { |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
479 let path = path.map_err(|e| v2_error(py, e))?; |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
480 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
|
481 dirs.append(py, path.into_object()) |
47351
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
482 } |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
483 Ok(dirs) |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
484 } |
3b9914b28133
dirstate-v2: Add --dirs to debugdirstate command
Simon Sapin <simon.sapin@octobus.net>
parents:
47335
diff
changeset
|
485 |
49120
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
486 def setparents_fixup(&self) -> PyResult<PyDict> { |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
487 let dict = PyDict::new(py); |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
488 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:
49112
diff
changeset
|
489 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:
49112
diff
changeset
|
490 dict.set_item( |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
491 py, |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
492 PyBytes::new(py, key.as_bytes()), |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
493 PyBytes::new(py, value.as_bytes()), |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
494 )?; |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
495 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
496 Ok(dict) |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
497 } |
3df46f3a3d6c
rust-dirstatemap: implement part of the `setparents` logic
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49112
diff
changeset
|
498 |
48023
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
499 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
|
500 let dirs = PyList::new(py, &[]); |
48023
357307feaf61
debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
501 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
|
502 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
|
503 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
|
504 let path = PyBytes::new(py, path.as_bytes()); |
48024
cedfe2606adf
debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents:
48023
diff
changeset
|
505 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:
48023
diff
changeset
|
506 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
|
507 } |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
508 Ok(dirs) |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
509 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
510 }); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
511 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
512 impl DirstateMap { |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
513 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
|
514 &'a self, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43208
diff
changeset
|
515 py: Python<'a>, |
48069
3d0a9c6e614d
dirstate: Remove the Rust abstraction DirstateMapMethods
Simon Sapin <simon.sapin@octobus.net>
parents:
48068
diff
changeset
|
516 ) -> RefMut<'a, OwningDirstateMap> { |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
517 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
|
518 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
519 fn translate_key( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
520 py: Python, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
521 res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
522 ) -> PyResult<Option<PyBytes>> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
523 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:
47332
diff
changeset
|
524 Ok(Some(PyBytes::new(py, f.as_bytes()))) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
525 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
526 fn translate_key_value( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
527 py: Python, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
528 res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
529 ) -> PyResult<Option<(PyBytes, PyObject)>> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
530 let (f, entry) = res.map_err(|e| v2_error(py, e))?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
531 Ok(Some(( |
44973
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44441
diff
changeset
|
532 PyBytes::new(py, f.as_bytes()), |
48044
d5528ac9b4f2
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
48024
diff
changeset
|
533 DirstateItem::new_as_pyobject(py, entry)?, |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44973
diff
changeset
|
534 ))) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44973
diff
changeset
|
535 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
536 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
537 |
42889
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42888
diff
changeset
|
538 py_shared_iterator!( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
539 DirstateMapKeysIterator, |
44234
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44233
diff
changeset
|
540 UnsafePyLeaked<StateMapIter<'static>>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
541 DirstateMap::translate_key, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
542 Option<PyBytes> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
543 ); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
544 |
42889
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42888
diff
changeset
|
545 py_shared_iterator!( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
546 DirstateMapItemsIterator, |
44234
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44233
diff
changeset
|
547 UnsafePyLeaked<StateMapIter<'static>>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
548 DirstateMap::translate_key_value, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
549 Option<(PyBytes, PyObject)> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
550 ); |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
551 |
52050
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
552 py_class!(pub class DirstateIdentity |py| { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
553 data inner: CoreDirstateIdentity; |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
554 |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
555 def __new__( |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
556 _cls, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
557 mode: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
558 dev: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
559 ino: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
560 nlink: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
561 uid: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
562 gid: u32, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
563 size: u64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
564 mtime: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
565 mtime_nsec: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
566 ctime: i64, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
567 ctime_nsec: i64) -> PyResult<DirstateIdentity> { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
568 Self::create_instance( |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
569 py, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
570 CoreDirstateIdentity { |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
571 mode, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
572 dev, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
573 ino, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
574 nlink, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
575 uid, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
576 gid, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
577 size, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
578 mtime, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
579 mtime_nsec, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
580 ctime, |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
581 ctime_nsec |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
582 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
583 ) |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
584 } |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
585 }); |
ea0467ed76aa
rust-dirstate-map: use a more precise identity
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52040
diff
changeset
|
586 |
46595
98a455a62699
rust: Make `DirstateParents`?s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46440
diff
changeset
|
587 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<Node> { |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
588 let bytes = obj.extract::<PyBytes>(py)?; |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
589 match bytes.data(py).try_into() { |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
590 Ok(s) => Ok(s), |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
591 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:
42799
diff
changeset
|
592 } |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
593 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
594 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
595 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:
47332
diff
changeset
|
596 PyErr::new::<exc::ValueError, _>(py, "corrupted dirstate-v2") |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
597 } |
47683
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
598 |
284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents:
47682
diff
changeset
|
599 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
|
600 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
|
601 } |