Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/copy_tracing.rs @ 46590:8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
? instead of acquiring the GIL in the Rust thread in the Drop impl
This commit is based on the premise that crossbeam-channel
with unbounded send and non-blocking receive is faster than
a contended GIL, but that remains to be measured.
Differential Revision: https://phab.mercurial-scm.org/D9686
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Tue, 05 Jan 2021 21:46:21 +0100 |
parents | 620c88fb42a2 |
children | 8f031a274cd6 |
rev | line source |
---|---|
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 use cpython::ObjectProtocol; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 use cpython::PyBytes; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 use cpython::PyDict; |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
4 use cpython::PyDrop; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 use cpython::PyList; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 use cpython::PyModule; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 use cpython::PyObject; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 use cpython::PyResult; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 use cpython::PyTuple; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 use cpython::Python; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 use hg::copy_tracing::ChangedFiles; |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
13 use hg::copy_tracing::CombineChangesetCopies; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 use hg::Revision; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
16 use self::pybytes_with_data::PyBytesWithData; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
17 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
18 // Module to encapsulate private fields |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
19 mod pybytes_with_data { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
20 use cpython::{PyBytes, Python}; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
21 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
22 /// Safe abstraction over a `PyBytes` together with the `&[u8]` slice |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
23 /// that borrows it. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
24 /// |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
25 /// Calling `PyBytes::data` requires a GIL marker but we want to access the |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
26 /// data in a thread that (ideally) does not need to acquire the GIL. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
27 /// This type allows separating the call an the use. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
28 pub(super) struct PyBytesWithData { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
29 #[allow(unused)] |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
30 keep_alive: PyBytes, |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
31 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
32 /// Borrows the buffer inside `self.keep_alive`, |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
33 /// but the borrow-checker cannot express self-referential structs. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
34 data: *const [u8], |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
35 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
36 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
37 fn require_send<T: Send>() {} |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
38 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
39 #[allow(unused)] |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
40 fn static_assert_pybytes_is_send() { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
41 require_send::<PyBytes>; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
42 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
43 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
44 // Safety: PyBytes is Send. Raw pointers are not by default, |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
45 // but here sending one to another thread is fine since we ensure it stays |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
46 // valid. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
47 unsafe impl Send for PyBytesWithData {} |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
48 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
49 impl PyBytesWithData { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
50 pub fn new(py: Python, bytes: PyBytes) -> Self { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
51 Self { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
52 data: bytes.data(py), |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
53 keep_alive: bytes, |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
54 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
55 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
56 |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
57 pub fn data(&self) -> &[u8] { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
58 // Safety: the raw pointer is valid as long as the PyBytes is still |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
59 // alive, and the returned slice borrows `self`. |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
60 unsafe { &*self.data } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
61 } |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
62 |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
63 pub fn unwrap(self) -> PyBytes { |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
64 self.keep_alive |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
65 } |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
66 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
67 } |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
68 |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 /// Combines copies information contained into revision `revs` to build a copy |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 /// map. |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 /// |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 /// See mercurial/copies.py for details |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 pub fn combine_changeset_copies_wrapper( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 py: Python, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 revs: PyList, |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
76 children_count: PyDict, |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 target_rev: Revision, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 rev_info: PyObject, |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
79 multi_thread: bool, |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 ) -> PyResult<PyDict> { |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
81 let children_count = children_count |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 .items(py) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 .iter() |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
84 .map(|(k, v)| Ok((k.extract(py)?, v.extract(py)?))) |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
85 .collect::<PyResult<_>>()?; |
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
86 |
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
87 /// (Revision number, parent 1, parent 2, copy data for this revision) |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
88 type RevInfo<Bytes> = (Revision, Revision, Revision, Option<Bytes>); |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
89 |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
90 let revs_info = |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
91 revs.iter(py).map(|rev_py| -> PyResult<RevInfo<PyBytes>> { |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
92 let rev = rev_py.extract(py)?; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
93 let tuple: PyTuple = |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
94 rev_info.call(py, (rev_py,), None)?.cast_into(py)?; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
95 let p1 = tuple.get_item(py, 0).extract(py)?; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
96 let p2 = tuple.get_item(py, 1).extract(py)?; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
97 let opt_bytes = tuple.get_item(py, 2).extract(py)?; |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
98 Ok((rev, p1, p2, opt_bytes)) |
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
99 }); |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
101 let path_copies; |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
102 if !multi_thread { |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
103 let mut combine_changeset_copies = |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
104 CombineChangesetCopies::new(children_count); |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
105 |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
106 for rev_info in revs_info { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
107 let (rev, p1, p2, opt_bytes) = rev_info?; |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
108 let files = match &opt_bytes { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
109 Some(bytes) => ChangedFiles::new(bytes.data(py)), |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
110 // Python None was extracted to Option::None, |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
111 // meaning there was no copy data. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
112 None => ChangedFiles::new_empty(), |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
113 }; |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
114 |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
115 combine_changeset_copies.add_revision(rev, p1, p2, files) |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
116 } |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
117 path_copies = combine_changeset_copies.finish(target_rev) |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
118 } else { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
119 // Use a bounded channel to provide back-pressure: |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
120 // if the child thread is slower to process revisions than this thread |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
121 // is to gather data for them, an unbounded channel would keep |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
122 // growing and eat memory. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
123 // |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
124 // TODO: tweak the bound? |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
125 let (rev_info_sender, rev_info_receiver) = |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
126 crossbeam_channel::bounded::<RevInfo<PyBytesWithData>>(1000); |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
127 |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
128 // This channel (going the other way around) however is unbounded. |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
129 // If they were both bounded, there might potentially be deadlocks |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
130 // where both channels are full and both threads are waiting on each |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
131 // other. |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
132 let (pybytes_sender, pybytes_receiver) = |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
133 crossbeam_channel::unbounded(); |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
134 |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
135 // Start a thread that does CPU-heavy processing in parallel with the |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
136 // loop below. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
137 // |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
138 // If the parent thread panics, `rev_info_sender` will be dropped and |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
139 // “disconnected”. `rev_info_receiver` will be notified of this and |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
140 // exit its own loop. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
141 let thread = std::thread::spawn(move || { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
142 let mut combine_changeset_copies = |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
143 CombineChangesetCopies::new(children_count); |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
144 for (rev, p1, p2, opt_bytes) in rev_info_receiver { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
145 let files = match &opt_bytes { |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
146 Some(raw) => ChangedFiles::new(raw.data()), |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
147 // Python None was extracted to Option::None, |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
148 // meaning there was no copy data. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
149 None => ChangedFiles::new_empty(), |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
150 }; |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
151 combine_changeset_copies.add_revision(rev, p1, p2, files); |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
152 |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
153 // Send `PyBytes` back to the parent thread so the parent |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
154 // thread can drop it. Otherwise the GIL would be implicitly |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
155 // acquired here through `impl Drop for PyBytes`. |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
156 if let Some(bytes) = opt_bytes { |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
157 if let Err(_) = pybytes_sender.send(bytes.unwrap()) { |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
158 // The channel is disconnected, meaning the parent |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
159 // thread panicked or returned |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
160 // early through |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
161 // `?` to propagate a Python exception. |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
162 break; |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
163 } |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
164 } |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
165 } |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
166 |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
167 combine_changeset_copies.finish(target_rev) |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
168 }); |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
169 |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
170 for rev_info in revs_info { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
171 let (rev, p1, p2, opt_bytes) = rev_info?; |
46589
620c88fb42a2
copies-rust: introduce PyBytesWithData to reduce GIL requirement
Simon Sapin <simon-commits@exyr.org>
parents:
46588
diff
changeset
|
172 let opt_bytes = opt_bytes.map(|b| PyBytesWithData::new(py, b)); |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
173 |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
174 // We’d prefer to avoid the child thread calling into Python code, |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
175 // but this avoids a potential deadlock on the GIL if it does: |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
176 py.allow_threads(|| { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
177 rev_info_sender.send((rev, p1, p2, opt_bytes)).expect( |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
178 "combine_changeset_copies: channel is disconnected", |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
179 ); |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
180 }); |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
181 |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
182 // Drop anything in the channel, without blocking |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
183 for pybytes in pybytes_receiver.try_iter() { |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
184 pybytes.release_ref(py) |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
185 } |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
186 } |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
187 // We’d prefer to avoid the child thread calling into Python code, |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
188 // but this avoids a potential deadlock on the GIL if it does: |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
189 path_copies = py.allow_threads(|| { |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
190 // Disconnect the channel to signal the child thread to stop: |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
191 // the `for … in rev_info_receiver` loop will end. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
192 drop(rev_info_sender); |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
193 |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
194 // Wait for the child thread to stop, and propagate any panic. |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
195 thread.join().unwrap_or_else(|panic_payload| { |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
196 std::panic::resume_unwind(panic_payload) |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
197 }) |
46590
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
198 }); |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
199 |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
200 // Drop anything left in the channel |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
201 for pybytes in pybytes_receiver.iter() { |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
202 pybytes.release_ref(py) |
8d20abed6a1e
copies-rust: send PyBytes values back be dropped ino the parent thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46589
diff
changeset
|
203 } |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
204 }; |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
205 |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
206 let out = PyDict::new(py); |
46587
cb4b0b0c6de4
copies-rust: split up combine_changeset_copies function into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46569
diff
changeset
|
207 for (dest, source) in path_copies.into_iter() { |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
208 out.set_item( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
209 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
210 PyBytes::new(py, &dest.into_vec()), |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
211 PyBytes::new(py, &source.into_vec()), |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
212 )?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
213 } |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
214 Ok(out) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
215 } |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
216 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
217 /// Create the module, with `__package__` given from parent |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
218 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
219 let dotted_name = &format!("{}.copy_tracing", package); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
220 let m = PyModule::new(py, dotted_name)?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
221 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
222 m.add(py, "__package__", package)?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
223 m.add(py, "__doc__", "Copy tracing - Rust implementation")?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
224 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
225 m.add( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
226 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
227 "combine_changeset_copies", |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
228 py_fn!( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
229 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
230 combine_changeset_copies_wrapper( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
231 revs: PyList, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
232 children: PyDict, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
233 target_rev: Revision, |
46588
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
234 rev_info: PyObject, |
47557ea79fc7
copies-rust: move CPU-heavy Rust processing into a child thread
Simon Sapin <simon.sapin@octobus.net>
parents:
46587
diff
changeset
|
235 multi_thread: bool |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
236 ) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
237 ), |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
238 )?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
239 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
240 let sys = PyModule::import(py, "sys")?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
241 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
242 sys_modules.set_item(py, dotted_name, &m)?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
243 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
244 Ok(m) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
245 } |