Mercurial > hg
annotate rust/hg-cpython/src/dirstate/dirstate_map.rs @ 47335:ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
When parsing becomes lazy, parse error will potentially happen in more places.
This propagates such errors to callers.
Differential Revision: https://phab.mercurial-scm.org/D10749
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 19 May 2021 13:15:00 +0200 |
parents | 4ee9f419c52e |
children | 3b9914b28133 |
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 |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
11 use std::cell::{RefCell, RefMut}; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 use std::convert::TryInto; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 use cpython::{ |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
15 exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, |
47121
b6339a993b91
rust: Remove handling of `parents` in `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
16 PyObject, PyResult, PySet, PyString, Python, PythonObject, ToPyObject, |
b6339a993b91
rust: Remove handling of `parents` in `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47112
diff
changeset
|
17 UnsafePyLeaked, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 }; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 use crate::{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
22 dirstate::non_normal_entries::{ |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
23 NonNormalEntries, NonNormalEntriesIterator, |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
24 }, |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
25 dirstate::owning::OwningDirstateMap, |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43180
diff
changeset
|
26 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
46595
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46440
diff
changeset
|
27 parsers::dirstate_parents_to_pytuple, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 }; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 use hg::{ |
47101
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
30 dirstate::parsers::Timestamp, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
31 dirstate_tree::dispatch::DirstateMapMethods, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
32 dirstate_tree::on_disk::DirstateV2ParseError, |
46440
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46227
diff
changeset
|
33 errors::HgError, |
46595
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46440
diff
changeset
|
34 revlog::Node, |
47109
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
35 utils::files::normalize_case, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
36 utils::hg_path::{HgPath, HgPathBuf}, |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
37 DirsMultiset, DirstateEntry, DirstateError, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
38 DirstateMap as RustDirstateMap, DirstateParents, EntryState, StateMapIter, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 }; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 // TODO |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 // 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
|
43 // 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
|
44 // 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
|
45 // 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
|
46 // every method in `CopyMap` (copymapcopy, etc.). |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 // 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
|
48 // 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
|
49 // `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
|
50 // `RustDirstateMap`, rightfully so. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 // 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
|
52 // 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
|
53 py_class!(pub class DirstateMap |py| { |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
54 @shared data inner: Box<dyn DirstateMapMethods + Send>; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
56 /// 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
|
57 @staticmethod |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
58 def new( |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
59 use_dirstate_tree: bool, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
60 use_dirstate_v2: bool, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
61 on_disk: PyBytes, |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
62 ) -> PyResult<PyObject> { |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
63 let dirstate_error = |e: DirstateError| { |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
64 PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e)) |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
65 }; |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
66 let (inner, parents) = if use_dirstate_tree || use_dirstate_v2 { |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
67 let (map, parents) = |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
68 OwningDirstateMap::new(py, on_disk, use_dirstate_v2) |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
69 .map_err(dirstate_error)?; |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
70 (Box::new(map) as _, parents) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
47094
diff
changeset
|
71 } else { |
47123
d8ac62374943
dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
72 let bytes = on_disk.data(py); |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
73 let mut map = RustDirstateMap::default(); |
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
74 let parents = map.read(bytes).map_err(dirstate_error)?; |
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
75 (Box::new(map) as _, parents) |
47095
473abf4728bf
dirstate-tree: Empty shell for a second Rust DirstateMap implementation
Simon Sapin <simon.sapin@octobus.net>
parents:
47094
diff
changeset
|
76 }; |
47122
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
77 let map = Self::create_instance(py, inner)?; |
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
78 let parents = parents.map(|p| dirstate_parents_to_pytuple(py, &p)); |
9aba0cde0ed9
rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents:
47121
diff
changeset
|
79 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
|
80 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 def clear(&self) -> PyResult<PyObject> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
83 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
|
84 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 def get( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 default: Option<PyObject> = None |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 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
|
93 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
94 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
95 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
96 .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
|
97 .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
|
98 { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 Some(entry) => { |
47332
4ee9f419c52e
rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
100 Ok(Some(make_dirstate_tuple(py, &entry)?)) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 }, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 None => Ok(default) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 def addfile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 oldstate: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 state: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 mode: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 size: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 mtime: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 ) -> PyResult<PyObject> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
115 self.inner(py).borrow_mut().add_file( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
116 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 .try_into() |
46440
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46227
diff
changeset
|
119 .map_err(|e: HgError| { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 })?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 DirstateEntry { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 state: state.extract::<PyBytes>(py)?.data(py)[0] |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 .try_into() |
46440
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46227
diff
changeset
|
125 .map_err(|e: HgError| { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 })?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 mode: mode.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 size: size.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 mtime: mtime.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 }, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
132 ).and(Ok(py.None())).or_else(|e: DirstateError| { |
43788
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
43430
diff
changeset
|
133 Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())) |
1fe2e574616e
rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents:
43430
diff
changeset
|
134 }) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 def removefile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 oldstate: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 size: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 ) -> PyResult<PyObject> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
143 self.inner(py).borrow_mut() |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 .remove_file( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
145 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 .try_into() |
46440
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46227
diff
changeset
|
148 .map_err(|e: HgError| { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 })?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 size.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 .or_else(|_| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
156 "Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
157 )) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
158 })?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
159 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
161 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
162 def dropfile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
163 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
165 oldstate: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 ) -> PyResult<PyBool> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
167 self.inner(py).borrow_mut() |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
168 .drop_file( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
169 HgPath::new(f.extract::<PyBytes>(py)?.data(py)), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
170 oldstate.extract::<PyBytes>(py)?.data(py)[0] |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
171 .try_into() |
46440
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46227
diff
changeset
|
172 .map_err(|e: HgError| { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 })?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
175 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 .and_then(|b| Ok(b.to_py_object(py))) |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
177 .or_else(|e| { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 py, |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
180 format!("Dirstate error: {}", e.to_string()), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 )) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 }) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 def clearambiguoustimes( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 files: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 now: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 ) -> PyResult<PyObject> { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
190 let files: PyResult<Vec<HgPathBuf>> = files |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 .iter(py)? |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 .map(|filename| { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
193 Ok(HgPathBuf::from_bytes( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
194 filename?.extract::<PyBytes>(py)?.data(py), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
195 )) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 }) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 .collect(); |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
198 self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
199 .borrow_mut() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
200 .clear_ambiguous_times(files?, now.extract(py)?) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
201 .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
|
202 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
205 def other_parent_entries(&self) -> PyResult<PyObject> { |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
44234
diff
changeset
|
206 let mut inner_shared = self.inner(py).borrow_mut(); |
46891
c6ceb5f27f97
rust: Remove use of `py.eval()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
207 let set = PySet::empty(py)?; |
47094
e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
208 for path in inner_shared.iter_other_parent_paths() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
209 let path = path.map_err(|e| v2_error(py, e))?; |
46891
c6ceb5f27f97
rust: Remove use of `py.eval()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
210 set.add(py, PyBytes::new(py, path.as_bytes()))?; |
c6ceb5f27f97
rust: Remove use of `py.eval()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
211 } |
c6ceb5f27f97
rust: Remove use of `py.eval()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46890
diff
changeset
|
212 Ok(set.into_object()) |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
213 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
214 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
215 def non_normal_entries(&self) -> PyResult<NonNormalEntries> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
216 NonNormalEntries::from_inner(py, self.clone_ref(py)) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
217 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
218 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
219 def non_normal_entries_contains(&self, key: PyObject) -> PyResult<bool> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
220 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
|
221 self.inner(py) |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
44234
diff
changeset
|
222 .borrow_mut() |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
223 .non_normal_entries_contains(HgPath::new(key.data(py))) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
224 .map_err(|e| v2_error(py, e)) |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
225 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
226 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
227 def non_normal_entries_display(&self) -> PyResult<PyString> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
228 let mut inner = self.inner(py).borrow_mut(); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
229 let paths = inner |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
230 .iter_non_normal_paths() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
231 .collect::<Result<Vec<_>, _>>() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
232 .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
|
233 let formatted = format!("NonNormalEntries: {}", hg::utils::join_display(paths, ", ")); |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
234 Ok(PyString::new(py, &formatted)) |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
235 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
236 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
237 def non_normal_entries_remove(&self, key: PyObject) -> PyResult<PyObject> { |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
238 let key = key.extract::<PyBytes>(py)?; |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
239 self |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
44234
diff
changeset
|
240 .inner(py) |
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
44234
diff
changeset
|
241 .borrow_mut() |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
242 .non_normal_entries_remove(HgPath::new(key.data(py))); |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
243 Ok(py.None()) |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
244 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
245 |
47094
e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
246 def non_normal_or_other_parent_paths(&self) -> PyResult<PyList> { |
e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
247 let mut inner = self.inner(py).borrow_mut(); |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
248 |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
249 let ret = PyList::new(py, &[]); |
47094
e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
250 for filename in inner.non_normal_or_other_parent_paths() { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
251 let filename = filename.map_err(|e| v2_error(py, e))?; |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
252 let as_pystring = PyBytes::new(py, filename.as_bytes()); |
44297
cf1f8660e568
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
44234
diff
changeset
|
253 ret.append(py, as_pystring.into_object()); |
44327
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
254 } |
71e13cfd6154
rust-dirstatemap: add `NonNormalEntries` class
Raphaël Gomès <rgomes@octobus.net>
parents:
43863
diff
changeset
|
255 Ok(ret) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
258 def non_normal_entries_iter(&self) -> PyResult<NonNormalEntriesIterator> { |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
259 // Make sure the sets are defined before we no longer have a mutable |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
260 // reference to the dmap. |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
261 self.inner(py) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
262 .borrow_mut() |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
263 .set_non_normal_other_parent_entries(false); |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
264 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
265 let leaked_ref = self.inner(py).leak_immutable(); |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
266 |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
267 NonNormalEntriesIterator::from_inner(py, unsafe { |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
268 leaked_ref.map(py, |o| { |
47094
e061a1df32a8
dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47093
diff
changeset
|
269 o.iter_non_normal_paths_panic() |
44416
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
270 }) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
271 }) |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
272 } |
8ac5726d695d
rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents:
44362
diff
changeset
|
273 |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
274 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
|
275 let d = d.extract::<PyBytes>(py)?; |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
276 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
|
277 .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
|
278 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
279 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
|
280 })? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 .to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 def hasdir(&self, d: PyObject) -> PyResult<PyBool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 let d = d.extract::<PyBytes>(py)?; |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
286 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
|
287 .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
|
288 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
289 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
|
290 })? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 .to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 def write( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 &self, |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
296 use_dirstate_v2: bool, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 p1: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 p2: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 now: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 ) -> PyResult<PyBytes> { |
47101
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
47095
diff
changeset
|
301 let now = Timestamp(now.extract(py)?); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 let parents = DirstateParents { |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
303 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
|
304 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
|
305 }; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 |
47280
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
307 let mut inner = self.inner(py).borrow_mut(); |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
308 let result = if use_dirstate_v2 { |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
309 inner.pack_v2(parents, now) |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
310 } else { |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
311 inner.pack_v1(parents, now) |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
312 }; |
1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents:
47124
diff
changeset
|
313 match result { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 Ok(packed) => Ok(PyBytes::new(py, &packed)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 Err(_) => Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 "Dirstate error".to_string(), |
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 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 def filefoldmapasdict(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 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
|
324 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
|
325 let (path, entry) = item.map_err(|e| v2_error(py, e))?; |
47109
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
326 if entry.state != EntryState::Removed { |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
327 let key = normalize_case(path); |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
328 let value = path; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
329 dict.set_item( |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
330 py, |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
331 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
|
332 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
|
333 )?; |
33e5511b571a
rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents:
47101
diff
changeset
|
334 } |
42754
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 Ok(dict) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 def __len__(&self) -> PyResult<usize> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
340 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
|
341 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 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
|
344 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
|
345 self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
346 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
347 .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
|
348 .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
|
349 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
350 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 let key = key.extract::<PyBytes>(py)?; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
353 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
|
354 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
355 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
356 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
357 .get(key) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
358 .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
|
359 { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 Some(entry) => { |
47332
4ee9f419c52e
rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47280
diff
changeset
|
361 Ok(make_dirstate_tuple(py, &entry)?) |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 }, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 py, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
365 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
|
366 )), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
368 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
371 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
|
372 DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
374 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
|
375 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
376 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 def items(&self) -> PyResult<DirstateMapItemsIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
379 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
|
380 DirstateMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
382 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
|
383 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
387 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
|
388 DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
389 py, |
43285
ffc1fbd7d1f5
rust-cpython: make PyLeakedRef operations relatively safe
Yuya Nishihara <yuya@tcha.org>
parents:
43284
diff
changeset
|
390 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
|
391 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 } |
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 def getdirs(&self) -> PyResult<Dirs> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 // TODO don't copy, share the reference |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
396 self.inner(py).borrow_mut().set_dirs() |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
397 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
398 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
|
399 })?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 Dirs::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 py, |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
402 DirsMultiset::from_dirstate( |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
403 self.inner(py).borrow().iter(), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 Some(EntryState::Removed), |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
405 ) |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
406 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
407 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
|
408 })?, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 def getalldirs(&self) -> PyResult<Dirs> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 // TODO don't copy, share the reference |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
413 self.inner(py).borrow_mut().set_all_dirs() |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
414 .map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
415 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
|
416 })?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 Dirs::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 py, |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
419 DirsMultiset::from_dirstate( |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
420 self.inner(py).borrow().iter(), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 None, |
43863
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
422 ).map_err(|e| { |
bc7d8f45c3b6
rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
423 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
|
424 })?, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
425 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
427 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
428 // 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
|
429 def copymapcopy(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 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
|
434 py, |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44441
diff
changeset
|
435 PyBytes::new(py, key.as_bytes()), |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44441
diff
changeset
|
436 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
|
437 )?; |
42754
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 Ok(dict) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
440 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
441 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
442 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
|
443 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
|
444 match self |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
445 .inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
446 .borrow() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
447 .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
|
448 .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
|
449 { |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44441
diff
changeset
|
450 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
|
451 None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 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
|
454 )), |
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 def copymap(&self) -> PyResult<CopyMap> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
458 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
|
459 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
461 def 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
|
462 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
|
463 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 .borrow() |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
468 .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
|
469 .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
|
470 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
471 def copymapget( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
473 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
474 default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
475 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
476 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
|
477 match self |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
478 .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
|
479 .borrow() |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
480 .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
|
481 .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
|
482 { |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42890
diff
changeset
|
483 Some(copy) => Ok(Some( |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44441
diff
changeset
|
484 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
|
485 )), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
486 None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
487 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
488 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
489 def copymapsetitem( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
490 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
491 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
492 value: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
493 ) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
494 let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
495 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
|
496 self.inner(py) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
497 .borrow_mut() |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
498 .copy_map_insert( |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
499 HgPathBuf::from_bytes(key.data(py)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
500 HgPathBuf::from_bytes(value.data(py)), |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
501 ) |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
502 .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
|
503 Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
504 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
505 def copymappop( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
506 &self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
507 key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
508 default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
509 ) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
510 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
|
511 match self |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
512 .inner(py) |
44203
2a24ead003f0
rust-cpython: add panicking version of borrow_mut() and use it
Yuya Nishihara <yuya@tcha.org>
parents:
43863
diff
changeset
|
513 .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
|
514 .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
|
515 .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
|
516 { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
517 Some(_) => Ok(None), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
518 None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
519 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
520 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
521 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
522 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
523 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
|
524 CopyMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
525 py, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
526 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
|
527 ) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
528 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
529 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
530 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
44233
281642cd1d04
rust-cpython: rename inner_shared() to inner()
Yuya Nishihara <yuya@tcha.org>
parents:
44203
diff
changeset
|
531 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
|
532 CopyMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
533 py, |
47093
787ff5d21bcd
dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents:
46891
diff
changeset
|
534 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
|
535 ) |
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 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
538 }); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
539 |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
540 impl DirstateMap { |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
541 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
|
542 &'a self, |
478d0b1bf0c5
rust-dirstate-status: rust-cpython bindings for `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
43208
diff
changeset
|
543 py: Python<'a>, |
47112
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
544 ) -> RefMut<'a, Box<dyn DirstateMapMethods + Send>> { |
d5956136d19d
dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
47109
diff
changeset
|
545 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
|
546 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
547 fn translate_key( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
548 py: Python, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
549 res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
550 ) -> PyResult<Option<PyBytes>> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
551 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
|
552 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
|
553 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
554 fn translate_key_value( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
555 py: Python, |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
556 res: Result<(&HgPath, DirstateEntry), DirstateV2ParseError>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
557 ) -> PyResult<Option<(PyBytes, PyObject)>> { |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
558 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
|
559 Ok(Some(( |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44441
diff
changeset
|
560 PyBytes::new(py, f.as_bytes()), |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
561 make_dirstate_tuple(py, &entry)?, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
562 ))) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
44973
diff
changeset
|
563 } |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
564 } |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
565 |
42889
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42888
diff
changeset
|
566 py_shared_iterator!( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
567 DirstateMapKeysIterator, |
44234
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44233
diff
changeset
|
568 UnsafePyLeaked<StateMapIter<'static>>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
569 DirstateMap::translate_key, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
570 Option<PyBytes> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
571 ); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
572 |
42889
ea91a126c803
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator
Yuya Nishihara <yuya@tcha.org>
parents:
42888
diff
changeset
|
573 py_shared_iterator!( |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
574 DirstateMapItemsIterator, |
44234
bad4e7b361d2
rust-cpython: switch to upstreamed version of PySharedRefCell
Yuya Nishihara <yuya@tcha.org>
parents:
44233
diff
changeset
|
575 UnsafePyLeaked<StateMapIter<'static>>, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
576 DirstateMap::translate_key_value, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
577 Option<(PyBytes, PyObject)> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
578 ); |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
579 |
46595
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46440
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 Ok(s) => Ok(s), |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
584 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
|
585 } |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
586 } |
47335
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
587 |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47332
diff
changeset
|
588 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
|
589 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
|
590 } |