Mercurial > hg
annotate rust/hg-cpython/src/dirstate.rs @ 43210:3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Fortunately, the layout of PyObject {} is compatible with a C pointer, but
we shouldn't rely on that. This also fixes the handling of NULL pointer.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 13 Oct 2019 17:01:10 +0900 |
parents | 8b355cbef16d |
children | 88a9930e92e4 |
rev | line source |
---|---|
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 // dirstate.rs |
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 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 //! Bindings for the `hg::dirstate` module provided by the |
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 //! |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 //! From Python, this will be seen as `mercurial.rustext.dirstate` |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
12 mod copymap; |
42746
b3518b0baa47
rust-dirstate: create dirstate submodule in hg-cpython
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
13 mod dirs_multiset; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
14 mod dirstate_map; |
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
15 use crate::dirstate::{dirs_multiset::Dirs, dirstate_map::DirstateMap}; |
42303
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 cpython::{ |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
17 exc, PyBytes, PyDict, PyErr, PyModule, PyObject, PyResult, PySequence, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
18 Python, |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 }; |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42754
diff
changeset
|
20 use hg::{ |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42754
diff
changeset
|
21 utils::hg_path::HgPathBuf, DirstateEntry, DirstateParseError, EntryState, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42754
diff
changeset
|
22 StateMap, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42754
diff
changeset
|
23 }; |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42558
diff
changeset
|
24 use libc::{c_char, c_int}; |
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42558
diff
changeset
|
25 #[cfg(feature = "python27")] |
43210
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
26 use python27_sys as python_sys; |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42558
diff
changeset
|
27 #[cfg(feature = "python3")] |
43210
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
28 use python3_sys as python_sys; |
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
29 use python_sys::PyCapsule_Import; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
30 use std::convert::TryFrom; |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 use std::ffi::CStr; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 use std::mem::transmute; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 /// C code uses a custom `dirstate_tuple` type, checks in multiple instances |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 /// for this type, and raises a Python `Exception` if the check does not pass. |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 /// Because this type differs only in name from the regular Python tuple, it |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 /// would be a good idea in the near future to remove it entirely to allow |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 /// for a pure Python tuple of the same effective structure to be used, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 /// rendering this type and the capsule below useless. |
43209
8b355cbef16d
rust-cpython: mark capsule function as unsafe
Yuya Nishihara <yuya@tcha.org>
parents:
43208
diff
changeset
|
40 type MakeDirstateTupleFn = unsafe extern "C" fn( |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 state: c_char, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 mode: c_int, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 size: c_int, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 mtime: c_int, |
43210
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
45 ) -> *mut python_sys::PyObject; |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 /// This is largely a copy/paste from cindex.rs, pending the merge of a |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 /// `py_capsule_fn!` macro in the rust-cpython project: |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 /// https://github.com/dgrunwald/rust-cpython/pull/169 |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
50 fn decapsule_make_dirstate_tuple(py: Python) -> PyResult<MakeDirstateTupleFn> { |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 unsafe { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 let caps_name = CStr::from_bytes_with_nul_unchecked( |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 b"mercurial.cext.parsers.make_dirstate_tuple_CAPI\0", |
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 let from_caps = PyCapsule_Import(caps_name.as_ptr(), 0); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 if from_caps.is_null() { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 return Err(PyErr::fetch(py)); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 Ok(transmute(from_caps)) |
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 } |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
63 pub fn make_dirstate_tuple( |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
64 py: Python, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
65 entry: &DirstateEntry, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
66 ) -> PyResult<PyObject> { |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
67 let make = decapsule_make_dirstate_tuple(py)?; |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
68 |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
69 let &DirstateEntry { |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
70 state, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
71 mode, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
72 size, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
73 mtime, |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
74 } = entry; |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
75 // Explicitly go through u8 first, then cast to platform-specific `c_char` |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
76 // because Into<u8> has a specific implementation while `as c_char` would |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
77 // just do a naive enum cast. |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
78 let state_code: u8 = state.into(); |
43209
8b355cbef16d
rust-cpython: mark capsule function as unsafe
Yuya Nishihara <yuya@tcha.org>
parents:
43208
diff
changeset
|
79 |
43210
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
80 let maybe_obj = unsafe { |
43209
8b355cbef16d
rust-cpython: mark capsule function as unsafe
Yuya Nishihara <yuya@tcha.org>
parents:
43208
diff
changeset
|
81 let ptr = make(state_code as c_char, mode, size, mtime); |
43210
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
82 PyObject::from_owned_ptr_opt(py, ptr) |
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
83 }; |
3fec5244aff1
rust-cpython: fix signature of make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
43209
diff
changeset
|
84 maybe_obj.ok_or_else(|| PyErr::fetch(py)) |
43208
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
85 } |
1ca3823aeefd
rust-cpython: add wrapper around decapsule_make_dirstate_tuple()
Yuya Nishihara <yuya@tcha.org>
parents:
42957
diff
changeset
|
86 |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42747
diff
changeset
|
87 pub fn extract_dirstate(py: Python, dmap: &PyDict) -> Result<StateMap, PyErr> { |
42537
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
88 dmap.items(py) |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 .iter() |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 .map(|(filename, stats)| { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 let stats = stats.extract::<PySequence>(py)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 let state = stats.get_item(py, 0)?.extract::<PyBytes>(py)?; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
93 let state = EntryState::try_from(state.data(py)[0]).map_err( |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
94 |e: DirstateParseError| { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
95 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
96 }, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
97 )?; |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 let mode = stats.get_item(py, 1)?.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
|
99 let size = stats.get_item(py, 2)?.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
|
100 let mtime = stats.get_item(py, 3)?.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
|
101 let filename = filename.extract::<PyBytes>(py)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 let filename = filename.data(py); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 Ok(( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42754
diff
changeset
|
104 HgPathBuf::from(filename.to_owned()), |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 DirstateEntry { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 state, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 mode, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 size, |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 mtime, |
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 )) |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 }) |
42537
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
113 .collect() |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
114 } |
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
115 |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 /// Create the module, with `__package__` given from parent |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 let dotted_name = &format!("{}.dirstate", package); |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 let m = PyModule::new(py, dotted_name)?; |
42537
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
120 |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 m.add(py, "__package__", package)?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 m.add(py, "__doc__", "Dirstate - Rust implementation")?; |
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 |
42537
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
124 m.add_class::<Dirs>(py)?; |
42754
4e8f504424f3
rust-dirstate: rust-cpython bridge for dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42749
diff
changeset
|
125 m.add_class::<DirstateMap>(py)?; |
42537
ce94f9622acd
rust-dirstate: add "dirs" rust-cpython binding
Raphaël Gomès <rgomes@octobus.net>
parents:
42408
diff
changeset
|
126 |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
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 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
|
132 } |