Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-cpython/src/parsers.rs @ 42764:7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Both `parse_dirstate` and `pack_dirstate` can operate directly on the data
they're passed, which prevents the creation of intermediate data structures,
simplifies the function signatures and reduces boilerplate. They are exposed
directly to the Python for now, but a later patch will make use of them inside
`hg-core`.
Differential Revision: https://phab.mercurial-scm.org/D6628
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 09 Jul 2019 11:49:49 +0200 |
parents | 760a7851e9ba |
children | 7ceded4419a3 |
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` |
760a7851e9ba
rust-parsers: move parser bindings to their own file and Python module
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42762
diff
changeset
|
12 //! |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
13 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
|
14 exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python, |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
15 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
|
16 }; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
17 use hg::{ |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
18 pack_dirstate, parse_dirstate, utils::copy_into_array, DirstateEntry, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
19 DirstatePackError, DirstateParents, DirstateParseError, 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 }; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
21 use std::collections::HashMap; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
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
|
23 use libc::c_char; |
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 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
25 use crate::dirstate::{decapsule_make_dirstate_tuple, extract_dirstate}; |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
26 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
|
27 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 ) -> PyResult<PyTuple> { |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
34 let mut dirstate_map = HashMap::new(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
35 let mut copies = HashMap::new(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
36 |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
37 match parse_dirstate(&mut dirstate_map, &mut copies, st.data(py)) { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
38 Ok(parents) => { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
39 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
|
40 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
|
41 py, |
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 PyBytes::new(py, &filename), |
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 decapsule_make_dirstate_tuple(py)?( |
42427
4e4fa3a95406
rust-dirstate: architecture independence fix
Georges Racinet <georges.racinet@octobus.net>
parents:
42378
diff
changeset
|
44 entry.state as c_char, |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
45 entry.mode, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
46 entry.size, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
47 entry.mtime, |
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 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
50 } |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
51 for (path, copy_path) in copies { |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
52 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
|
53 py, |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
54 PyBytes::new(py, &path), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
55 PyBytes::new(py, ©_path), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
56 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
57 } |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
58 Ok( |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
59 (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
|
60 .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
|
61 ) |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
62 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
63 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
|
64 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
65 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
|
66 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
|
67 "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
|
68 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
69 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
|
70 "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
|
71 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
72 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
|
73 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
|
74 "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
|
75 } |
42330
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 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
42544
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
81 fn pack_dirstate_wrapper( |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
82 py: Python, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
83 dmap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
84 copymap: PyDict, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
85 pl: PyTuple, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
86 now: PyInt, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
87 ) -> PyResult<PyBytes> { |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 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
|
92 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
93 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
|
94 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
95 let copies: Result<HashMap<Vec<u8>, Vec<u8>>, PyErr> = copymap |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
96 .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
|
97 .iter() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
98 .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
|
99 Ok(( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
100 key.extract::<PyBytes>(py)?.data(py).to_owned(), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
101 value.extract::<PyBytes>(py)?.data(py).to_owned(), |
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 }) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
104 .collect(); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
106 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
|
107 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
|
108 py, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
109 "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
|
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 } |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
112 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
113 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
|
114 &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
|
115 &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
|
116 DirstateParents { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
117 p1: copy_into_array(&p1), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
118 p2: copy_into_array(&p2), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
119 }, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
120 Duration::from_secs(now.value(py) as u64), |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
121 ) { |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
122 Ok(packed) => { |
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 for ( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
124 filename, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
125 DirstateEntry { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
126 state, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
127 mode, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
128 size, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
129 mtime, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
130 }, |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42763
diff
changeset
|
131 ) 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
|
132 { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
133 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
|
134 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
135 PyBytes::new(py, &filename[..]), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
136 decapsule_make_dirstate_tuple(py)?( |
42544
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
137 state as c_char, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
138 mode, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
139 size, |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Rapha?l Gom?s <rgomes@octobus.net>
parents:
42427
diff
changeset
|
140 mtime, |
42330
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 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
|
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 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
|
147 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
148 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
|
149 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
|
150 "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
|
151 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
156 }, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
157 )), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
158 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
159 } |
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 /// 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
|
162 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
|
163 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
|
164 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
|
165 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
166 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
|
167 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
|
168 |
42330
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
169 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
|
170 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
171 "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
|
172 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
|
173 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
174 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
|
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 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
177 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
|
178 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
179 "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
|
180 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
|
181 py, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 ) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
188 ), |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
189 )?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff
changeset
|
195 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
|
196 } |