author | Simon Sapin <simon.sapin@octobus.net> |
Fri, 21 May 2021 17:12:47 +0200 | |
changeset 47327 | e985a36c2aa3 |
parent 47115 | 5d62243c7732 |
child 47357 | 3b9914b28133 |
permissions | -rw-r--r-- |
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
1 |
// parsers.rs |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
// This software may be used and distributed according to the terms of the |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
// GNU General Public License version 2 or any later version. |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 |
|
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
8 |
//! Bindings for the `hg::dirstate::parsers` module provided by the |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 |
//! `hg-core` package. |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 |
//! |
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
11 |
//! From Python, this will be seen as `mercurial.rustext.parsers` |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 |
use cpython::{ |
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
13 |
exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python, |
42809
98901eb12245
rust-parsers: fix unboxing of PyInt on Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
42765
diff
changeset
|
14 |
PythonObject, ToPyObject, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
}; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
use hg::{ |
47115
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
46634
diff
changeset
|
17 |
dirstate::parsers::Timestamp, pack_dirstate, parse_dirstate, |
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
46634
diff
changeset
|
18 |
utils::hg_path::HgPathBuf, DirstateEntry, DirstateParents, FastHashMap, |
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
46634
diff
changeset
|
19 |
PARENT_SIZE, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
}; |
42815
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42809
diff
changeset
|
21 |
use std::convert::TryInto; |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
|
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42960
diff
changeset
|
23 |
use crate::dirstate::{extract_dirstate, make_dirstate_tuple}; |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
|
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
fn parse_dirstate_wrapper( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
py: Python, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 |
dmap: PyDict, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
copymap: PyDict, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
st: PyBytes, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 |
) -> PyResult<PyTuple> { |
45377
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
31 |
match parse_dirstate(st.data(py)) { |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
32 |
Ok((parents, entries, copies)) => { |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
33 |
let dirstate_map: FastHashMap<HgPathBuf, DirstateEntry> = entries |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
34 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
35 |
.map(|(path, entry)| (path.to_owned(), entry)) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
36 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
37 |
let copy_map: FastHashMap<HgPathBuf, HgPathBuf> = copies |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
38 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
39 |
.map(|(path, copy)| (path.to_owned(), copy.to_owned())) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
40 |
.collect(); |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
41 |
|
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42960
diff
changeset
|
42 |
for (filename, entry) in &dirstate_map { |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
dmap.set_item( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
py, |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
43844
diff
changeset
|
45 |
PyBytes::new(py, filename.as_bytes()), |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42960
diff
changeset
|
46 |
make_dirstate_tuple(py, entry)?, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
} |
45377
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
49 |
for (path, copy_path) in copy_map { |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
copymap.set_item( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 |
py, |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
43844
diff
changeset
|
52 |
PyBytes::new(py, path.as_bytes()), |
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
43844
diff
changeset
|
53 |
PyBytes::new(py, copy_path.as_bytes()), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
} |
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
56 |
Ok(dirstate_parents_to_pytuple(py, parents)) |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
} |
46508
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
46507
diff
changeset
|
58 |
Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
} |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
} |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
|
42544
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
62 |
fn pack_dirstate_wrapper( |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
63 |
py: Python, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
64 |
dmap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
65 |
copymap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
66 |
pl: PyTuple, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
67 |
now: PyInt, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
68 |
) -> PyResult<PyBytes> { |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
69 |
let p1 = pl.get_item(py, 0).extract::<PyBytes>(py)?; |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
70 |
let p1: &[u8] = p1.data(py); |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
71 |
let p2 = pl.get_item(py, 1).extract::<PyBytes>(py)?; |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
72 |
let p2: &[u8] = p2.data(py); |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
73 |
|
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
74 |
let mut dirstate_map = extract_dirstate(py, &dmap)?; |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
|
43844
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43836
diff
changeset
|
76 |
let copies: Result<FastHashMap<HgPathBuf, HgPathBuf>, PyErr> = copymap |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
.items(py) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
.iter() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
.map(|(key, value)| { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
Ok(( |
42960
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42818
diff
changeset
|
81 |
HgPathBuf::from_bytes(key.extract::<PyBytes>(py)?.data(py)), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42818
diff
changeset
|
82 |
HgPathBuf::from_bytes(value.extract::<PyBytes>(py)?.data(py)), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 |
)) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
}) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
.collect(); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 |
|
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
87 |
if p1.len() != PARENT_SIZE || p2.len() != PARENT_SIZE { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
88 |
return Err(PyErr::new::<exc::ValueError, _>( |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
89 |
py, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
90 |
"expected a 20-byte hash".to_string(), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
91 |
)); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
92 |
} |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
93 |
|
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
match pack_dirstate( |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
95 |
&mut dirstate_map, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
&copies?, |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
97 |
DirstateParents { |
42815
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42809
diff
changeset
|
98 |
p1: p1.try_into().unwrap(), |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42809
diff
changeset
|
99 |
p2: p2.try_into().unwrap(), |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
100 |
}, |
47115
5d62243c7732
rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents:
46634
diff
changeset
|
101 |
Timestamp(now.as_object().extract::<u64>(py)?), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
) { |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42763
diff
changeset
|
103 |
Ok(packed) => { |
45613
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45377
diff
changeset
|
104 |
for (filename, entry) in dirstate_map.iter() { |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
dmap.set_item( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
py, |
44998
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
43844
diff
changeset
|
107 |
PyBytes::new(py, filename.as_bytes()), |
45613
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45377
diff
changeset
|
108 |
make_dirstate_tuple(py, &entry)?, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
} |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 |
Ok(PyBytes::new(py, &packed)) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
} |
46507
68a15b5a7e58
rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
113 |
Err(error) => { |
68a15b5a7e58
rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
114 |
Err(PyErr::new::<exc::ValueError, _>(py, error.to_string())) |
68a15b5a7e58
rust: Replace DirstatePackError with HgError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
115 |
} |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
} |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 |
} |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
|
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
/// Create the module, with `__package__` given from parent |
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
120 |
pub fn init_parsers_module(py: Python, package: &str) -> PyResult<PyModule> { |
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
121 |
let dotted_name = &format!("{}.parsers", package); |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 |
let m = PyModule::new(py, dotted_name)?; |
42544
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42427
diff
changeset
|
123 |
|
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
m.add(py, "__package__", package)?; |
42763
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
125 |
m.add(py, "__doc__", "Parsers - Rust implementation")?; |
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents:
42762
diff
changeset
|
126 |
|
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
m.add( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 |
py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 |
"parse_dirstate", |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
py_fn!( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
parse_dirstate_wrapper(dmap: PyDict, copymap: PyDict, st: PyBytes) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 |
), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 |
)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 |
m.add( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 |
py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
"pack_dirstate", |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 |
py_fn!( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 |
py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
pack_dirstate_wrapper( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
dmap: PyDict, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
copymap: PyDict, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 |
pl: PyTuple, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
now: PyInt |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 |
)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 |
|
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 |
let sys = PyModule::import(py, "sys")?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
151 |
sys_modules.set_item(py, dotted_name, &m)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
|
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
153 |
Ok(m) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 |
} |
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
155 |
|
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
156 |
pub(crate) fn dirstate_parents_to_pytuple( |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
157 |
py: Python, |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
158 |
parents: &DirstateParents, |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
159 |
) -> PyTuple { |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
160 |
let p1 = PyBytes::new(py, parents.p1.as_bytes()); |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
161 |
let p2 = PyBytes::new(py, parents.p2.as_bytes()); |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
162 |
(p1, p2).to_py_object(py) |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
163 |
} |