author | Yuya Nishihara <yuya@tcha.org> |
Sun, 01 Sep 2019 17:35:14 +0900 | |
changeset 42846 | 01d3ce3281cf |
parent 42802 | 2e1f74cc3350 |
child 42849 | 8db8fa1de2ef |
permissions | -rw-r--r-- |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
use std::cell::RefCell; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 |
use std::convert::TryInto; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 |
use std::time::Duration; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
use cpython::{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
PyResult, PyTuple, Python, PythonObject, ToPyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
}; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
use libc::c_char; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
use crate::{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
dirstate::{decapsule_make_dirstate_tuple, dirs_multiset::Dirs}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
ref_sharing::PySharedState, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
}; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
use hg::{ |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
27 |
DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
28 |
DirstateParents, DirstateParseError, EntryState, PARENT_SIZE, |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
}; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 |
// TODO |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
// This object needs to share references to multiple members of its Rust |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
// inner struct, namely `copy_map`, `dirs` and `all_dirs`. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
// Right now `CopyMap` is done, but it needs to have an explicit reference |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
// to `RustDirstateMap` which itself needs to have an encapsulation for |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
// every method in `CopyMap` (copymapcopy, etc.). |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
// This is ugly and hard to maintain. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
// The same logic applies to `dirs` and `all_dirs`, however the `Dirs` |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
// `py_class!` is already implemented and does not mention |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
// `RustDirstateMap`, rightfully so. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 |
// All attributes also have to have a separate refcount data attribute for |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
// leaks, with all methods that go along for reference sharing. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
py_class!(pub class DirstateMap |py| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
data inner: RefCell<RustDirstateMap>; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
data py_shared_state: PySharedState; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
def __new__(_cls, _root: PyObject) -> PyResult<Self> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
let inner = RustDirstateMap::default(); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
Self::create_instance( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
RefCell::new(inner), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
PySharedState::default() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 |
def clear(&self) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
self.borrow_mut(py)?.clear(); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
def get( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
default: Option<PyObject> = None |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
match self.inner(py).borrow().get(key.data(py)) { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
Some(entry) => { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
// Explicitly go through u8 first, then cast to |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
// platform-specific `c_char`. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
let state: u8 = entry.state.into(); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
Ok(Some(decapsule_make_dirstate_tuple(py)?( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
state as c_char, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
entry.mode, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
entry.size, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 |
entry.mtime, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
None => Ok(default) |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 |
def addfile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
oldstate: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 |
state: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
mode: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 |
size: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 |
mtime: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
self.borrow_mut(py)?.add_file( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
f.extract::<PyBytes>(py)?.data(py), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
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
|
95 |
.try_into() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
.map_err(|e: DirstateParseError| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
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
|
98 |
})?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 |
DirstateEntry { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
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
|
101 |
.try_into() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
.map_err(|e: DirstateParseError| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
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
|
104 |
})?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
mode: mode.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
size: size.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 |
mtime: mtime.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 |
}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
def removefile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 |
f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
oldstate: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 |
size: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
self.borrow_mut(py)? |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
.remove_file( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 |
f.extract::<PyBytes>(py)?.data(py), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 |
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
|
123 |
.try_into() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
.map_err(|e: DirstateParseError| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 |
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
|
126 |
})?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
size.extract(py)?, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 |
.or_else(|_| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
"Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 |
)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
})?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
Ok(py.None()) |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 |
def dropfile( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
f: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
oldstate: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
) -> PyResult<PyBool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 |
self.borrow_mut(py)? |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
.drop_file( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
f.extract::<PyBytes>(py)?.data(py), |
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() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 |
.map_err(|e: DirstateParseError| { |
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 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
.and_then(|b| Ok(b.to_py_object(py))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
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 |
} |
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 |
def clearambiguoustimes( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
162 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
163 |
files: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 |
now: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
165 |
) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 |
let files: PyResult<Vec<Vec<u8>>> = files |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
167 |
.iter(py)? |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
168 |
.map(|filename| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
169 |
Ok(filename?.extract::<PyBytes>(py)?.data(py).to_owned()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
170 |
}) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
171 |
.collect(); |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
172 |
self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 |
.clear_ambiguous_times(files?, now.extract(py)?); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 |
Ok(py.None()) |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 |
// TODO share the reference |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 |
def nonnormalentries(&self) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 |
let (non_normal, other_parent) = |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 |
self.inner(py).borrow().non_normal_other_parent_entries(); |
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 |
let locals = PyDict::new(py); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 |
locals.set_item( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 |
"non_normal", |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 |
non_normal |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 |
.iter() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 |
.map(|v| PyBytes::new(py, &v)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 |
.collect::<Vec<PyBytes>>() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
.to_py_object(py), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 |
locals.set_item( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 |
"other_parent", |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
other_parent |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 |
.iter() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 |
.map(|v| PyBytes::new(py, &v)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 |
.collect::<Vec<PyBytes>>() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
.to_py_object(py), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 |
)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
201 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 |
py.eval("set(non_normal), set(other_parent)", None, Some(&locals)) |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
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
|
206 |
let d = d.extract::<PyBytes>(py)?; |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
207 |
Ok(self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
.has_tracked_dir(d.data(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 |
.to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 |
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
|
213 |
let d = d.extract::<PyBytes>(py)?; |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
214 |
Ok(self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 |
.has_dir(d.data(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 |
.to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
217 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 |
def parents(&self, st: PyObject) -> PyResult<PyTuple> { |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
220 |
self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 |
.parents(st.extract::<PyBytes>(py)?.data(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 |
.and_then(|d| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
224 |
.to_py_object(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
225 |
}) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
.or_else(|_| { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 |
Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 |
"Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 |
)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
}) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 |
def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
235 |
let 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
|
236 |
let 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
|
237 |
|
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
238 |
self.borrow_mut(py)? |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42800
diff
changeset
|
239 |
.set_parents(&DirstateParents { p1, p2 }); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
244 |
match self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 |
.read(st.extract::<PyBytes>(py)?.data(py)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 |
{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
Ok(Some(parents)) => Ok(Some( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 |
(PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
249 |
.to_py_object(py) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 |
.into_object(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
Ok(None) => Ok(Some(py.None())), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
253 |
Err(_) => Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 |
"Dirstate error".to_string(), |
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 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 |
def write( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 |
p1: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 |
p2: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 |
now: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 |
) -> PyResult<PyBytes> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 |
let now = Duration::new(now.extract(py)?, 0); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 |
let parents = DirstateParents { |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
}; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
match self.borrow_mut(py)?.pack(parents, now) { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 |
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
|
273 |
Err(_) => Err(PyErr::new::<exc::OSError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
274 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 |
"Dirstate error".to_string(), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 |
def filefoldmapasdict(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 |
let dict = PyDict::new(py); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 |
for (key, value) in |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 |
self.borrow_mut(py)?.build_file_fold_map().iter() |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 |
{ |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
dict.set_item(py, key, value)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 |
Ok(dict) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
def __len__(&self) -> PyResult<usize> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 |
Ok(self.inner(py).borrow().len()) |
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 __contains__(&self, key: PyObject) -> PyResult<bool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 |
Ok(self.inner(py).borrow().contains_key(key.data(py))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 |
def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
301 |
let key = key.data(py); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 |
match self.inner(py).borrow().get(key) { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 |
Some(entry) => { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 |
// Explicitly go through u8 first, then cast to |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 |
// platform-specific `c_char`. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 |
let state: u8 = entry.state.into(); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 |
Ok(decapsule_make_dirstate_tuple(py)?( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 |
state as c_char, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 |
entry.mode, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 |
entry.size, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 |
entry.mtime, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 |
)) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 |
}, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 |
None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 |
String::from_utf8_lossy(key), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
319 |
} |
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 |
def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 |
DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 |
Some(DirstateMapLeakedRef::new(py, &self)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 |
Box::new(self.leak_immutable(py)?.iter()), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 |
def items(&self) -> PyResult<DirstateMapItemsIterator> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 |
DirstateMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 |
Some(DirstateMapLeakedRef::new(py, &self)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 |
Box::new(self.leak_immutable(py)?.iter()), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 |
def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 |
DirstateMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
Some(DirstateMapLeakedRef::new(py, &self)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 |
Box::new(self.leak_immutable(py)?.iter()), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
345 |
def getdirs(&self) -> PyResult<Dirs> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
346 |
// TODO don't copy, share the reference |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
347 |
self.borrow_mut(py)?.set_dirs(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 |
Dirs::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 |
py, |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
350 |
DirsMultiset::from_dirstate( |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
351 |
&self.inner(py).borrow(), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 |
Some(EntryState::Removed), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
353 |
), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
354 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
355 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 |
def getalldirs(&self) -> PyResult<Dirs> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
357 |
// TODO don't copy, share the reference |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
358 |
self.borrow_mut(py)?.set_all_dirs(); |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 |
Dirs::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 |
py, |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
361 |
DirsMultiset::from_dirstate( |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
362 |
&self.inner(py).borrow(), |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 |
None, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 |
), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 |
) |
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 |
// 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
|
369 |
def copymapcopy(&self) -> PyResult<PyDict> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 |
let dict = PyDict::new(py); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
for (key, value) in self.inner(py).borrow().copy_map.iter() { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 |
dict.set_item(py, PyBytes::new(py, key), PyBytes::new(py, value))?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
Ok(dict) |
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 |
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
|
378 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
match self.inner(py).borrow().copy_map.get(key.data(py)) { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
Some(copy) => Ok(PyBytes::new(py, copy)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
None => Err(PyErr::new::<exc::KeyError, _>( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
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
|
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 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 |
def copymap(&self) -> PyResult<CopyMap> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 |
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
|
389 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 |
def copymaplen(&self) -> PyResult<usize> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
Ok(self.inner(py).borrow().copy_map.len()) |
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 copymapcontains(&self, key: PyObject) -> PyResult<bool> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 |
Ok(self.inner(py).borrow().copy_map.contains_key(key.data(py))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
398 |
def copymapget( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 |
default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
403 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 |
match self.inner(py).borrow().copy_map.get(key.data(py)) { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 |
Some(copy) => Ok(Some(PyBytes::new(py, copy).into_object())), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 |
None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
def copymapsetitem( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 |
value: PyObject |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 |
) -> PyResult<PyObject> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
414 |
let key = key.extract::<PyBytes>(py)?; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 |
let value = value.extract::<PyBytes>(py)?; |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
416 |
self.borrow_mut(py)? |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 |
.copy_map |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 |
.insert(key.data(py).to_vec(), value.data(py).to_vec()); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
419 |
Ok(py.None()) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
420 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 |
def copymappop( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 |
&self, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
423 |
key: PyObject, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
424 |
default: Option<PyObject> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
425 |
) -> PyResult<Option<PyObject>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 |
let key = key.extract::<PyBytes>(py)?; |
42846
01d3ce3281cf
rust-cpython: fix unsafe inner(py).borrow_mut() calls
Yuya Nishihara <yuya@tcha.org>
parents:
42802
diff
changeset
|
427 |
match self.borrow_mut(py)?.copy_map.remove(key.data(py)) { |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
428 |
Some(_) => Ok(None), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
429 |
None => Ok(default), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
430 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
431 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
432 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
433 |
def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
434 |
CopyMapKeysIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
435 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
436 |
Some(DirstateMapLeakedRef::new(py, &self)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
437 |
Box::new(self.leak_immutable(py)?.copy_map.iter()), |
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 |
} |
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 |
def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
442 |
CopyMapItemsIterator::from_inner( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
443 |
py, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
444 |
Some(DirstateMapLeakedRef::new(py, &self)), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
445 |
Box::new(self.leak_immutable(py)?.copy_map.iter()), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
446 |
) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
447 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
448 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
449 |
}); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
450 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
451 |
impl DirstateMap { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 |
fn translate_key( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 |
py: Python, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
454 |
res: (&Vec<u8>, &DirstateEntry), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
455 |
) -> PyResult<Option<PyBytes>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
456 |
Ok(Some(PyBytes::new(py, res.0))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
457 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
458 |
fn translate_key_value( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 |
py: Python, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 |
res: (&Vec<u8>, &DirstateEntry), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
461 |
) -> PyResult<Option<(PyBytes, PyObject)>> { |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
462 |
let (f, entry) = res; |
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 |
// Explicitly go through u8 first, then cast to |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
465 |
// platform-specific `c_char`. |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
466 |
let state: u8 = entry.state.into(); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
467 |
Ok(Some(( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
468 |
PyBytes::new(py, f), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
469 |
decapsule_make_dirstate_tuple(py)?( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
470 |
state as c_char, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
471 |
entry.mode, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 |
entry.size, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
473 |
entry.mtime, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
474 |
), |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
475 |
))) |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
476 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
477 |
} |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
478 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
479 |
py_shared_ref!(DirstateMap, RustDirstateMap, inner, DirstateMapLeakedRef,); |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
480 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
481 |
py_shared_mapping_iterator!( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
482 |
DirstateMapKeysIterator, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
483 |
DirstateMapLeakedRef, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
484 |
Vec<u8>, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
485 |
DirstateEntry, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
486 |
DirstateMap::translate_key, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
487 |
Option<PyBytes> |
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 |
|
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
490 |
py_shared_mapping_iterator!( |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
491 |
DirstateMapItemsIterator, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
492 |
DirstateMapLeakedRef, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
493 |
Vec<u8>, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
494 |
DirstateEntry, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
495 |
DirstateMap::translate_key_value, |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
496 |
Option<(PyBytes, PyObject)> |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
497 |
); |
42800
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
498 |
|
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
499 |
fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> { |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
Ok(s) => Ok(s), |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
503 |
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
|
504 |
} |
79561843729a
rust-dirstate: handle invalid length of p1/p2 parameters
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
505 |
} |