Mercurial > hg
annotate rust/hg-cpython/src/lib.rs @ 50976:9929c8a73488
rust-revlog: split logic for `rawdata` to prepare for `UncheckedRevision` use
In the next changeset, we will change the logic to use `UncheckedRevision`
in the non-general delta case. The general delta case will use the "checked"
path since `base_rev_or_base_of_delta_chain` will be checked.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 11 Sep 2023 11:52:33 +0200 |
parents | 136aa80aa8b2 |
children | 4c5f6e95df84 |
rev | line source |
---|---|
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
1 // lib.rs |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
2 // |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
3 // Copyright 2018 Georges Racinet <gracinet@anybox.fr> |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
4 // |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
7 |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
8 //! Python bindings of `hg-core` objects using the `cpython` crate. |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
9 //! Once compiled, the resulting single shared library object can be placed in |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
10 //! the `mercurial` package directly as `rustext.so` or `rustext.dll`. |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
11 //! It holds several modules, so that from the point of view of Python, |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
12 //! it behaves as the `cext` package. |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
13 //! |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
14 //! Example: |
41184
dcf818267bc1
rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents:
41130
diff
changeset
|
15 //! |
dcf818267bc1
rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents:
41130
diff
changeset
|
16 //! ```text |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
17 //! >>> from mercurial.rustext import ancestor |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
18 //! >>> ancestor.__doc__ |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
19 //! 'Generic DAG ancestor algorithms - Rust implementation' |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
20 //! ``` |
49932
136aa80aa8b2
rust-clippy: disable some lints crate-wide for `hg-cpython`
Raphaël Gomès <rgomes@octobus.net>
parents:
48839
diff
changeset
|
21 #![allow(clippy::too_many_arguments)] // rust-cpython macros |
136aa80aa8b2
rust-clippy: disable some lints crate-wide for `hg-cpython`
Raphaël Gomès <rgomes@octobus.net>
parents:
48839
diff
changeset
|
22 #![allow(clippy::zero_ptr)] // rust-cpython macros |
136aa80aa8b2
rust-clippy: disable some lints crate-wide for `hg-cpython`
Raphaël Gomès <rgomes@octobus.net>
parents:
48839
diff
changeset
|
23 #![allow(clippy::needless_update)] // rust-cpython macros |
136aa80aa8b2
rust-clippy: disable some lints crate-wide for `hg-cpython`
Raphaël Gomès <rgomes@octobus.net>
parents:
48839
diff
changeset
|
24 #![allow(clippy::manual_strip)] // rust-cpython macros |
136aa80aa8b2
rust-clippy: disable some lints crate-wide for `hg-cpython`
Raphaël Gomès <rgomes@octobus.net>
parents:
48839
diff
changeset
|
25 #![allow(clippy::type_complexity)] // rust-cpython macros |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
26 |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
27 /// This crate uses nested private macros, `extern crate` is still needed in |
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42557
diff
changeset
|
28 /// 2018 edition. |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
29 #[macro_use] |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
30 extern crate cpython; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
31 |
41184
dcf818267bc1
rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents:
41130
diff
changeset
|
32 pub mod ancestors; |
41052
4c25038c112c
rust-cpython: implement Graph using C parents function
Georges Racinet <gracinet@anybox.fr>
parents:
40965
diff
changeset
|
33 mod cindex; |
41240
ff333620a4cc
rust-cpython: moved generic conversion fn out of ancestors module
Georges Racinet <georges.racinet@octobus.net>
parents:
41184
diff
changeset
|
34 mod conversion; |
42752
30320c7bf79f
rust-cpython: add macro for sharing references
Raphaël Gomès <rgomes@octobus.net>
parents:
42747
diff
changeset
|
35 #[macro_use] |
30320c7bf79f
rust-cpython: add macro for sharing references
Raphaël Gomès <rgomes@octobus.net>
parents:
42747
diff
changeset
|
36 pub mod ref_sharing; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
37 pub mod copy_tracing; |
41694
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41240
diff
changeset
|
38 pub mod dagops; |
44531
d4f19eb471ca
rust-cpython: add `debug` module to expose debug information to Python
Raphaël Gomès <rgomes@octobus.net>
parents:
44137
diff
changeset
|
39 pub mod debug; |
42557
d26e4a434fe5
rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents:
42357
diff
changeset
|
40 pub mod dirstate; |
42179
13b64247f48f
rust-discovery: cpython bindings for the core logic
Georges Racinet <georges.racinet@octobus.net>
parents:
41694
diff
changeset
|
41 pub mod discovery; |
41184
dcf818267bc1
rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents:
41130
diff
changeset
|
42 pub mod exceptions; |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
45945
diff
changeset
|
43 mod pybytes_deref; |
43945
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43289
diff
changeset
|
44 pub mod revlog; |
43251
970978975574
rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
42819
diff
changeset
|
45 pub mod utils; |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
46 |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
47 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| { |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
48 m.add( |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
49 py, |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
50 "__doc__", |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
51 "Mercurial core concepts - Rust implementation", |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
52 )?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
53 |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
54 let dotted_name: String = m.get(py, "__name__")?.extract(py)?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
55 m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?; |
41694
0c7b353ce100
rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents:
41240
diff
changeset
|
56 m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?; |
44531
d4f19eb471ca
rust-cpython: add `debug` module to expose debug information to Python
Raphaël Gomès <rgomes@octobus.net>
parents:
44137
diff
changeset
|
57 m.add(py, "debug", debug::init_module(py, &dotted_name)?)?; |
45945
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
58 m.add( |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
59 py, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
60 "copy_tracing", |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
61 copy_tracing::init_module(py, &dotted_name)?, |
50c5ee3bdf9a
copies: introduce the hg-cpython wrapper for `combine_changeset_copies`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44531
diff
changeset
|
62 )?; |
42179
13b64247f48f
rust-discovery: cpython bindings for the core logic
Georges Racinet <georges.racinet@octobus.net>
parents:
41694
diff
changeset
|
63 m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?; |
42303
e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
Raphaël Gomès <rgomes@octobus.net>
parents:
42179
diff
changeset
|
64 m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
65 m.add(py, "revlog", revlog::init_module(py, &dotted_name)?)?; |
40965
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
66 m.add(py, "GraphError", py.get_type::<exceptions::GraphError>())?; |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
67 Ok(()) |
5532823e8c18
rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff
changeset
|
68 }); |
43289
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
69 |
48839
7b068abe4aa2
rust: jettison Python 2 support
Augie Fackler <augie@google.com>
parents:
48020
diff
changeset
|
70 #[cfg(not(feature = "python3-bin"))] |
43289
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
71 #[test] |
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
72 #[ignore] |
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
73 fn libpython_must_be_linked_to_run_tests() { |
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
74 // stub function to tell that some tests wouldn't run |
8d432d3a2d7c
rust-cpython: prepare for writing tests that require libpython
Yuya Nishihara <yuya@tcha.org>
parents:
43251
diff
changeset
|
75 } |