Mercurial > hg
annotate rust/hg-cpython/src/copy_tracing.rs @ 46334:4b0192f592cf
share: move share safe functionality out of experimental
The share-safe functionality is complete and all configuration options are
implemented. The behavior is well discussed on mailing list and in reviews.
Let's unmark this as experimental to solve a chichen and egg issue.
Differential Revision: https://phab.mercurial-scm.org/D9823
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 18 Jan 2021 19:16:49 +0530 |
parents | 294d5aca4ff5 |
children | 34827c95092c |
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::PyBool; |
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::PyBytes; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 use cpython::PyDict; |
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::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
|
13 use hg::copy_tracing::ChangedFiles; |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
14 use hg::copy_tracing::DataHolder; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 use hg::copy_tracing::RevInfo; |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
16 use hg::copy_tracing::RevInfoMaker; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 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
|
18 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 /// 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
|
20 /// map. |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 /// |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 /// 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
|
23 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
|
24 py: Python, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 revs: PyList, |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
26 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
|
27 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
|
28 rev_info: PyObject, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 is_ancestor: PyObject, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 ) -> PyResult<PyDict> { |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 let revs: PyResult<_> = |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 revs.iter(py).map(|r| Ok(r.extract(py)?)).collect(); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 // Wrap the `is_ancestor` python callback as a Rust closure |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 // |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 // No errors are expected from the Python side, and they will should only |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 // happens in case of programing error or severe data corruption. Such |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 // errors will raise panic and the rust-cpython harness will turn them into |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 // Python exception. |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 let is_ancestor_wrap = |anc: Revision, desc: Revision| -> bool { |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 is_ancestor |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 .call(py, (anc, desc), None) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 .expect( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 "rust-copy-tracing: python call to `is_ancestor` \ |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 failed", |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 ) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 .cast_into::<PyBool>(py) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 .expect( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 "rust-copy-tracing: python call to `is_ancestor` \ |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 returned unexpected non-Bool value", |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 ) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 .is_true() |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 }; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 // Wrap the `rev_info_maker` python callback as a Rust closure |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 // |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 // No errors are expected from the Python side, and they will should only |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 // happens in case of programing error or severe data corruption. Such |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 // errors will raise panic and the rust-cpython harness will turn them into |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 // Python exception. |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
61 let rev_info_maker: RevInfoMaker<PyBytes> = |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
62 Box::new(|rev: Revision, d: &mut DataHolder<PyBytes>| -> RevInfo { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
63 let res: PyTuple = rev_info |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
64 .call(py, (rev,), None) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
65 .expect("rust-copy-tracing: python call to `rev_info` failed") |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 .cast_into(py) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 .expect( |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
68 "rust-copy_tracing: python call to `rev_info` returned \ |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
69 unexpected non-Tuple value", |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 ); |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
71 let p1 = res.get_item(py, 0).extract(py).expect( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
72 "rust-copy-tracing: rev_info return is invalid, first item \ |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
73 is a not a revision", |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 ); |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
75 let p2 = res.get_item(py, 1).extract(py).expect( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
76 "rust-copy-tracing: rev_info return is invalid, first item \ |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
77 is a not a revision", |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 ); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
80 let files = match res.get_item(py, 2).extract::<PyBytes>(py) { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
81 Ok(raw) => { |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
82 // Give responsability for the raw bytes lifetime to |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
83 // hg-core |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
84 d.data = Some(raw); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
85 let addrs = d.data.as_ref().expect( |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
86 "rust-copy-tracing: failed to get a reference to the \ |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
87 raw bytes for copy data").data(py); |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
88 ChangedFiles::new(addrs) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
89 } |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
90 // value was presumably None, meaning they was no copy data. |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
91 Err(_) => ChangedFiles::new_empty(), |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
92 }; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
94 (p1, p2, files) |
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
95 }); |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
96 let children_count: PyResult<_> = 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
|
97 .items(py) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 .iter() |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
99 .map(|(k, v)| Ok((k.extract(py)?, v.extract(py)?))) |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 .collect(); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 let res = 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
|
103 revs?, |
46149
294d5aca4ff5
copies: iterate over children directly (instead of parents)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46057
diff
changeset
|
104 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
|
105 target_rev, |
46057
e0313b0a6f7e
copies-rust: parse the changed-file sidedata directly in rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45945
diff
changeset
|
106 rev_info_maker, |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 &is_ancestor_wrap, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 ); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 let out = PyDict::new(py); |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 for (dest, source) in res.into_iter() { |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 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
|
112 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 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
|
114 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
|
115 )?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 } |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 Ok(out) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 } |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 /// 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
|
121 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
|
122 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
|
123 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
|
124 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 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
|
126 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
|
127 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 m.add( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 "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
|
131 py_fn!( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 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
|
134 revs: PyList, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 children: PyDict, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 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
|
137 rev_info: PyObject, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 is_ancestor: PyObject |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 ) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 ), |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 )?; |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 Ok(m) |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 } |