Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-cpython/src/parsers.rs @ 45613:496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
The previous patch added the `dirstate-tree` feature gate to enable the two
dirstate implementations to co-habit while the tree-based one gets better.
This patch copies over the code that differs, be it because the algorithm
changed or because the borrowing rules are different.
Indeed, `DirstateTree` is not observationally equivalent to the std `HashMap` in
the APIs we use: it does not have the `Entry` API (yet?) and its iterator
returns owned values instead of references. This last point is because the
implementation needs to be changed to a more clever and efficient solution.
Differential Revision: https://phab.mercurial-scm.org/D9133
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 30 Sep 2020 18:10:29 +0200 |
parents | 27424779c5b8 |
children | 68a15b5a7e58 |
rev | line source |
---|---|
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::{ |
45377
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
17 pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry, |
43844
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43836
diff
changeset
|
18 DirstatePackError, DirstateParents, DirstateParseError, FastHashMap, |
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43836
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}; |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
24 use std::time::Duration; |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
25 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 ) -> 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
|
32 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
|
33 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
|
34 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
|
35 .into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
36 .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
|
37 .collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
38 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
|
39 .into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
40 .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
|
41 .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
|
42 |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42960
diff
changeset
|
43 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
|
44 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
|
45 py, |
44998
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43844
diff
changeset
|
46 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
|
47 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
|
48 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
49 } |
45377
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44998
diff
changeset
|
50 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
|
51 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
|
52 py, |
44998
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43844
diff
changeset
|
53 PyBytes::new(py, path.as_bytes()), |
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43844
diff
changeset
|
54 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
|
55 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 } |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
57 Ok( |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
58 (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
59 .to_py_object(py), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
60 ) |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
61 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 Err(e) => Err(PyErr::new::<exc::ValueError, _>( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
64 match e { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 DirstateParseError::TooLittleData => { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
66 "too little data for parents".to_string() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
67 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
68 DirstateParseError::Overflow => { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 "overflow in dirstate".to_string() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
70 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
71 DirstateParseError::CorruptedEntry(e) => e, |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
72 DirstateParseError::Damaged => { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
73 "dirstate appears to be damaged".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
|
74 } |
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 }, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
76 )), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
77 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
78 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
42544
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
80 fn pack_dirstate_wrapper( |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
81 py: Python, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
82 dmap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
83 copymap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
84 pl: PyTuple, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
85 now: PyInt, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
86 ) -> PyResult<PyBytes> { |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
92 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
|
93 |
43844
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43836
diff
changeset
|
94 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
|
95 .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
|
96 .iter() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
97 .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
|
98 Ok(( |
42960
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42818
diff
changeset
|
99 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
|
100 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
|
101 )) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
102 }) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
103 .collect(); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
105 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
|
106 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
|
107 py, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
108 "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
|
109 )); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
110 } |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
111 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
112 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
|
113 &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
|
114 &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
|
115 DirstateParents { |
42815
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42809
diff
changeset
|
116 p1: p1.try_into().unwrap(), |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42809
diff
changeset
|
117 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
|
118 }, |
42809
98901eb12245
rust-parsers: fix unboxing of PyInt on Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
42765
diff
changeset
|
119 Duration::from_secs(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
|
120 ) { |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 py, |
44998
26114bd6ec60
rust: do a clippy pass
Rapha?l Gom?s <rgomes@octobus.net>
parents:
43844
diff
changeset
|
125 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
|
126 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
|
127 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
128 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
129 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
|
130 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
131 Err(error) => Err(PyErr::new::<exc::ValueError, _>( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
132 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
133 match error { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
134 DirstatePackError::CorruptedParent => { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
135 "expected a 20-byte hash".to_string() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
136 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
137 DirstatePackError::CorruptedEntry(e) => e, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
138 DirstatePackError::BadSize(expected, actual) => { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
139 format!("bad dirstate size: {} != {}", actual, expected) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
140 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
141 }, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
142 )), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
143 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
144 } |
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 /// 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
|
147 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
|
148 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
|
149 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
|
150 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
151 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
|
152 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
|
153 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
154 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
|
155 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
156 "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
|
157 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
|
158 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
159 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
|
160 ), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
161 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
162 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
|
163 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
164 "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
|
165 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
|
166 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 ) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
173 ), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
174 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
175 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
180 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
|
181 } |