annotate rust/hg-cpython/src/revlog.rs @ 51216:f6403bcd9f96

rust-index: synchronize remove to Rust index Future steps will bring the two indexes further together until we can rip the C index entirely when running Rust code.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 28 Jun 2023 16:43:39 +0200
parents f0fa98752d67
children f95f70cf2ee2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43951
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 // revlog.rs
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 //
44516
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
3 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
43951
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 //
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 // This software may be used and distributed according to the terms of the
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 // GNU General Public License version 2 or any later version.
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
8 use crate::{
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
9 cindex,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
10 utils::{node_from_py_bytes, node_from_py_object},
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
11 PyRevision,
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
12 };
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
13 use cpython::{
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
14 buffer::{Element, PyBuffer},
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
15 exc::{IndexError, ValueError},
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
16 ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule,
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
17 PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject,
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
18 };
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
19 use hg::{
51212
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
20 index::IndexHeader,
51213
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
21 index::{RevisionDataParams, COMPRESSION_MODE_INLINE},
44519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
22 nodemap::{Block, NodeMapError, NodeTree},
46500
18a261b11b20 rust: Remove hex parsing from the nodemap
Simon Sapin <simon.sapin@octobus.net>
parents: 46499
diff changeset
23 revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex},
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
24 BaseRevision, Revision, UncheckedRevision,
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
25 };
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
26 use std::cell::RefCell;
43951
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
27
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
28 /// Return a Struct implementing the Graph trait
44070
451d22174b5f revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents: 44015
diff changeset
29 pub(crate) fn pyindex_to_graph(
451d22174b5f revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents: 44015
diff changeset
30 py: Python,
451d22174b5f revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents: 44015
diff changeset
31 index: PyObject,
451d22174b5f revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents: 44015
diff changeset
32 ) -> PyResult<cindex::Index> {
44014
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44013
diff changeset
33 match index.extract::<MixedIndex>(py) {
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44013
diff changeset
34 Ok(midx) => Ok(midx.clone_cindex(py)),
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44013
diff changeset
35 Err(_) => cindex::Index::new(py, index),
c627f1b2f3c3 rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44013
diff changeset
36 }
43951
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
37 }
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
38
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
39 py_class!(pub class MixedIndex |py| {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
40 data cindex: RefCell<cindex::Index>;
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
41 data index: RefCell<hg::index::Index>;
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
42 data nt: RefCell<Option<NodeTree>>;
44519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
43 data docket: RefCell<Option<PyObject>>;
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
44 // Holds a reference to the mmap'ed persistent nodemap data
51207
8ade5e6cdb61 rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51118
diff changeset
45 data nodemap_mmap: RefCell<Option<PyBuffer>>;
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
46 // Holds a reference to the mmap'ed persistent index data
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
47 data index_mmap: RefCell<Option<PyBuffer>>;
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
48
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
49 def __new__(
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
50 _cls,
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
51 cindex: PyObject,
51212
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
52 data: PyObject,
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
53 default_header: u32,
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
54 ) -> PyResult<MixedIndex> {
51212
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
55 Self::new(py, cindex, data, default_header)
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
56 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
57
44015
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
58 /// Compatibility layer used for Python consumers needing access to the C index
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
59 ///
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
60 /// Only use case so far is `scmutil.shortesthexnodeidprefix`,
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
61 /// that may need to build a custom `nodetree`, based on a specified revset.
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
62 /// With a Rust implementation of the nodemap, we will be able to get rid of
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
63 /// this, by exposing our own standalone nodemap class,
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
64 /// ready to accept `MixedIndex`.
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
65 def get_cindex(&self) -> PyResult<PyObject> {
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
66 Ok(self.cindex(py).borrow().inner().clone_ref(py))
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
67 }
443dc1655923 rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 44014
diff changeset
68
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
69 // Index API involving nodemap, as defined in mercurial/pure/parsers.py
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
70
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
71 /// Return Revision if found, raises a bare `error.RevlogError`
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
72 /// in case of ambiguity, same as C version does
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
73 def get_rev(&self, node: PyBytes) -> PyResult<Option<PyRevision>> {
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
74 let opt = self.get_nodetree(py)?.borrow();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
75 let nt = opt.as_ref().unwrap();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
76 let idx = &*self.cindex(py).borrow();
47894
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
77 let node = node_from_py_bytes(py, &node)?;
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
78 let res = nt.find_bin(idx, node.into());
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
79 Ok(res.map_err(|e| nodemap_error(py, e))?.map(Into::into))
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
80 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
81
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
82 /// same as `get_rev()` but raises a bare `error.RevlogError` if node
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
83 /// is not found.
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
84 ///
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
85 /// No need to repeat `node` in the exception, `mercurial/revlog.py`
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
86 /// will catch and rewrap with it
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
87 def rev(&self, node: PyBytes) -> PyResult<PyRevision> {
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
88 self.get_rev(py, node)?.ok_or_else(|| revlog_error(py))
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
89 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
90
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
91 /// return True if the node exist in the index
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
92 def has_node(&self, node: PyBytes) -> PyResult<bool> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
93 self.get_rev(py, node).map(|opt| opt.is_some())
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
94 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
95
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
96 /// find length of shortest hex nodeid of a binary ID
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
97 def shortest(&self, node: PyBytes) -> PyResult<usize> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
98 let opt = self.get_nodetree(py)?.borrow();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
99 let nt = opt.as_ref().unwrap();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
100 let idx = &*self.cindex(py).borrow();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
101 match nt.unique_prefix_len_node(idx, &node_from_py_bytes(py, &node)?)
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
102 {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
103 Ok(Some(l)) => Ok(l),
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
104 Ok(None) => Err(revlog_error(py)),
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
105 Err(e) => Err(nodemap_error(py, e)),
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
106 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
107 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
108
47894
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
109 def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> {
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
110 let opt = self.get_nodetree(py)?.borrow();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
111 let nt = opt.as_ref().unwrap();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
112 let idx = &*self.cindex(py).borrow();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
113
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
114 let node_as_string = if cfg!(feature = "python3-sys") {
47894
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
115 node.cast_as::<PyString>(py)?.to_string(py)?.to_string()
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
116 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
117 else {
47894
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
118 let node = node.extract::<PyBytes>(py)?;
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
119 String::from_utf8_lossy(node.data(py)).to_string()
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
120 };
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
121
49373
455fce57e89e rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47894
diff changeset
122 let prefix = NodePrefix::from_hex(&node_as_string)
455fce57e89e rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47894
diff changeset
123 .map_err(|_| PyErr::new::<ValueError, _>(
455fce57e89e rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47894
diff changeset
124 py, format!("Invalid node or prefix '{}'", node_as_string))
455fce57e89e rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47894
diff changeset
125 )?;
46500
18a261b11b20 rust: Remove hex parsing from the nodemap
Simon Sapin <simon.sapin@octobus.net>
parents: 46499
diff changeset
126
47894
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
127 nt.find_bin(idx, prefix)
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
128 // TODO make an inner API returning the node directly
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
129 .map(|opt| opt.map(
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
130 |rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes())))
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
131 .map_err(|e| nodemap_error(py, e))
aa88fb60ecb4 rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents: 47795
diff changeset
132
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
133 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
134
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
135 /// append an index entry
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
136 def append(&self, tup: PyTuple) -> PyResult<PyObject> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
137 if tup.len(py) < 8 {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
138 // this is better than the panic promised by tup.get_item()
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
139 return Err(
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
140 PyErr::new::<IndexError, _>(py, "tuple index out of range"))
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
141 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
142 let node_bytes = tup.get_item(py, 7).extract(py)?;
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
143 let node = node_from_py_object(py, &node_bytes)?;
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
144
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
145 let rev = self.len(py)? as BaseRevision;
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
146 let mut idx = self.cindex(py).borrow_mut();
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
147
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
148 // This is ok since we will just add the revision to the index
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
149 let rev = Revision(rev);
51213
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
150 idx.append(py, tup.clone_ref(py))?;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
151 self.index(py)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
152 .borrow_mut()
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
153 .append(py_tuple_to_revision_data_params(py, tup)?)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
154 .unwrap();
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
155 self.get_nodetree(py)?.borrow_mut().as_mut().unwrap()
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
156 .insert(&*idx, &node, rev)
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
157 .map_err(|e| nodemap_error(py, e))?;
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
158 Ok(py.None())
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
159 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
160
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
161 def __delitem__(&self, key: PyObject) -> PyResult<()> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
162 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]`
51216
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
163 self.cindex(py).borrow().inner().del_item(py, &key)?;
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
164 let start = key.getattr(py, "start")?;
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
165 let start = UncheckedRevision(start.extract(py)?);
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
166 let start = self.index(py)
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
167 .borrow()
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
168 .check_revision(start)
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
169 .ok_or_else(|| {
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
170 nodemap_error(py, NodeMapError::RevisionNotInIndex(start))
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
171 })?;
f6403bcd9f96 rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51215
diff changeset
172 self.index(py).borrow_mut().remove(start).unwrap();
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
173 let mut opt = self.get_nodetree(py)?.borrow_mut();
49987
58074252db3c rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49373
diff changeset
174 let nt = opt.as_mut().unwrap();
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
175 nt.invalidate_all();
49987
58074252db3c rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49373
diff changeset
176 self.fill_nodemap(py, nt)?;
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
177 Ok(())
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
178 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
179
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
180 //
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
181 // Reforwarded C index API
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
182 //
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
183
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
184 // index_methods (tp_methods). Same ordering as in revlog.c
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
185
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
186 /// return the gca set of the given revs
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
187 def ancestors(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
188 self.call_cindex(py, "ancestors", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
189 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
190
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
191 /// return the heads of the common ancestors of the given revs
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
192 def commonancestorsheads(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
193 self.call_cindex(py, "commonancestorsheads", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
194 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
195
44521
cadcc8c20860 rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents: 44520
diff changeset
196 /// Clear the index caches and inner py_class data.
cadcc8c20860 rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents: 44520
diff changeset
197 /// It is Python's responsibility to call `update_nodemap_data` again.
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
198 def clearcaches(&self, *args, **kw) -> PyResult<PyObject> {
44521
cadcc8c20860 rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents: 44520
diff changeset
199 self.nt(py).borrow_mut().take();
cadcc8c20860 rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents: 44520
diff changeset
200 self.docket(py).borrow_mut().take();
51207
8ade5e6cdb61 rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51118
diff changeset
201 self.nodemap_mmap(py).borrow_mut().take();
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
202 self.call_cindex(py, "clearcaches", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
203 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
204
47075
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46974
diff changeset
205 /// return the raw binary string representing a revision
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46974
diff changeset
206 def entry_binary(&self, *args, **kw) -> PyResult<PyObject> {
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46974
diff changeset
207 self.call_cindex(py, "entry_binary", args, kw)
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46974
diff changeset
208 }
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46974
diff changeset
209
47078
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47075
diff changeset
210 /// return a binary packed version of the header
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47075
diff changeset
211 def pack_header(&self, *args, **kw) -> PyResult<PyObject> {
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47075
diff changeset
212 self.call_cindex(py, "pack_header", args, kw)
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47075
diff changeset
213 }
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47075
diff changeset
214
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
215 /// get an index entry
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
216 def get(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
217 self.call_cindex(py, "get", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
218 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
219
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
220 /// compute phases
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
221 def computephasesmapsets(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
222 self.call_cindex(py, "computephasesmapsets", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
223 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
224
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
225 /// reachableroots
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
226 def reachableroots2(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
227 self.call_cindex(py, "reachableroots2", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
228 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
229
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
230 /// get head revisions
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
231 def headrevs(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
232 self.call_cindex(py, "headrevs", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
233 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
234
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
235 /// get filtered head revisions
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
236 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
237 self.call_cindex(py, "headrevsfiltered", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
238 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
239
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
240 /// True if the object is a snapshot
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
241 def issnapshot(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
242 self.call_cindex(py, "issnapshot", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
243 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
244
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
245 /// Gather snapshot data in a cache dict
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
246 def findsnapshots(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
247 self.call_cindex(py, "findsnapshots", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
248 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
249
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
250 /// determine revisions with deltas to reconstruct fulltext
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
251 def deltachain(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
252 self.call_cindex(py, "deltachain", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
253 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
254
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
255 /// slice planned chunk read to reach a density threshold
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
256 def slicechunktodensity(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
257 self.call_cindex(py, "slicechunktodensity", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
258 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
259
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
260 /// stats for the index
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
261 def stats(&self, *args, **kw) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
262 self.call_cindex(py, "stats", args, kw)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
263 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
264
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
265 // index_sequence_methods and index_mapping_methods.
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
266 //
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
267 // Since we call back through the high level Python API,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
268 // there's no point making a distinction between index_get
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
269 // and index_getitem.
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
270
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
271 def __len__(&self) -> PyResult<usize> {
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
272 self.len(py)
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
273 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
274
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
275 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
276 // this conversion seems needless, but that's actually because
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
277 // `index_getitem` does not handle conversion from PyLong,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
278 // which expressions such as [e for e in index] internally use.
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
279 // Note that we don't seem to have a direct way to call
44521
cadcc8c20860 rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents: 44520
diff changeset
280 // PySequence_GetItem (does the job), which would possibly be better
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
281 // for performance
50988
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
282 let key = match key.extract::<i32>(py) {
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
283 Ok(rev) => rev.to_py_object(py).into_object(),
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
284 Err(_) => key,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
285 };
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
286 self.cindex(py).borrow().inner().get_item(py, key)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
287 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
288
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
289 def __contains__(&self, item: PyObject) -> PyResult<bool> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
290 // ObjectProtocol does not seem to provide contains(), so
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
291 // this is an equivalent implementation of the index_contains()
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
292 // defined in revlog.c
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
293 let cindex = self.cindex(py).borrow();
50988
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
294 match item.extract::<i32>(py) {
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
295 Ok(rev) => {
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
296 Ok(rev >= -1 && rev < self.len(py)? as BaseRevision)
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
297 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
298 Err(_) => {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
299 cindex.inner().call_method(
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
300 py,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
301 "has_node",
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
302 PyTuple::new(py, &[item]),
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
303 None)?
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
304 .extract(py)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
305 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
306 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
307 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
308
44518
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
309 def nodemap_data_all(&self) -> PyResult<PyBytes> {
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
310 self.inner_nodemap_data_all(py)
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
311 }
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
312
44519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
313 def nodemap_data_incremental(&self) -> PyResult<PyObject> {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
314 self.inner_nodemap_data_incremental(py)
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
315 }
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
316 def update_nodemap_data(
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
317 &self,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
318 docket: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
319 nm_data: PyObject
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
320 ) -> PyResult<PyObject> {
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
321 self.inner_update_nodemap_data(py, docket, nm_data)
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
322 }
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
323
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
324 @property
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
325 def entry_size(&self) -> PyResult<PyInt> {
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
326 self.cindex(py).borrow().inner().getattr(py, "entry_size")?.extract::<PyInt>(py)
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46500
diff changeset
327 }
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
328
47279
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
329 @property
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
330 def rust_ext_compat(&self) -> PyResult<PyInt> {
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
331 self.cindex(py).borrow().inner().getattr(py, "rust_ext_compat")?.extract::<PyInt>(py)
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
332 }
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
333
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
334 });
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
335
51208
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
336 /// Take a (potentially) mmap'ed buffer, and return the underlying Python
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
337 /// buffer along with the Rust slice into said buffer. We need to keep the
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
338 /// Python buffer around, otherwise we'd get a dangling pointer once the buffer
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
339 /// is freed from Python's side.
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
340 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
341 /// # Safety
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
342 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
343 /// The caller must make sure that the buffer is kept around for at least as
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
344 /// long as the slice.
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
345 #[deny(unsafe_op_in_unsafe_fn)]
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
346 unsafe fn mmap_keeparound(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
347 py: Python,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
348 data: PyObject,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
349 ) -> PyResult<(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
350 PyBuffer,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
351 Box<dyn std::ops::Deref<Target = [u8]> + Send + 'static>,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
352 )> {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
353 let buf = PyBuffer::get(py, &data)?;
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
354 let len = buf.item_count();
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
355
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
356 // Build a slice from the mmap'ed buffer data
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
357 let cbuf = buf.buf_ptr();
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
358 let bytes = if std::mem::size_of::<u8>() == buf.item_size()
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
359 && buf.is_c_contiguous()
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
360 && u8::is_compatible_format(buf.format())
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
361 {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
362 unsafe { std::slice::from_raw_parts(cbuf as *const u8, len) }
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
363 } else {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
364 return Err(PyErr::new::<ValueError, _>(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
365 py,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
366 "Nodemap data buffer has an invalid memory representation"
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
367 .to_string(),
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
368 ));
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
369 };
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
370
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
371 Ok((buf, Box::new(bytes)))
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
372 }
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
373
51213
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
374 fn py_tuple_to_revision_data_params(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
375 py: Python,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
376 tuple: PyTuple,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
377 ) -> PyResult<RevisionDataParams> {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
378 if tuple.len(py) < 8 {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
379 // this is better than the panic promised by tup.get_item()
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
380 return Err(PyErr::new::<IndexError, _>(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
381 py,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
382 "tuple index out of range",
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
383 ));
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
384 }
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
385 let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
386 let node_id = tuple
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
387 .get_item(py, 7)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
388 .extract::<PyBytes>(py)?
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
389 .data(py)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
390 .try_into()
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
391 .unwrap();
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
392 let flags = (offset_or_flags & 0xFFFF) as u16;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
393 let data_offset = offset_or_flags >> 16;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
394 Ok(RevisionDataParams {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
395 flags,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
396 data_offset,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
397 data_compressed_length: tuple.get_item(py, 1).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
398 data_uncompressed_length: tuple.get_item(py, 2).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
399 data_delta_base: tuple.get_item(py, 3).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
400 link_rev: tuple.get_item(py, 4).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
401 parent_rev_1: tuple.get_item(py, 5).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
402 parent_rev_2: tuple.get_item(py, 6).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
403 node_id,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
404 _sidedata_offset: 0,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
405 _sidedata_compressed_length: 0,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
406 data_compression_mode: COMPRESSION_MODE_INLINE,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
407 _sidedata_compression_mode: COMPRESSION_MODE_INLINE,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
408 _rank: -1,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
409 })
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
410 }
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
411
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
412 impl MixedIndex {
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
413 fn new(
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
414 py: Python,
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
415 cindex: PyObject,
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
416 data: PyObject,
51212
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
417 header: u32,
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
418 ) -> PyResult<MixedIndex> {
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
419 // Safety: we keep the buffer around inside the class as `index_mmap`
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
420 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? };
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
421
44513
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
422 Self::create_instance(
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
423 py,
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
424 RefCell::new(cindex::Index::new(py, cindex)?),
51212
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
425 RefCell::new(
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
426 hg::index::Index::new(
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
427 bytes,
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
428 IndexHeader::parse(&header.to_be_bytes())
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
429 .expect("default header is broken")
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
430 .unwrap(),
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
431 )
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
432 .unwrap(),
13f58ce70299 rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
433 ),
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
434 RefCell::new(None),
44519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
435 RefCell::new(None),
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
436 RefCell::new(None),
51211
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
437 RefCell::new(Some(buf)),
44513
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
438 )
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
439 }
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
440
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
441 fn len(&self, py: Python) -> PyResult<usize> {
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
442 let rust_index_len = self.index(py).borrow().len();
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
443 let cindex_len = self.cindex(py).borrow().inner().len(py)?;
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
444 assert_eq!(rust_index_len, cindex_len);
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
445 Ok(cindex_len)
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
446 }
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
447
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
448 /// This is scaffolding at this point, but it could also become
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
449 /// a way to start a persistent nodemap or perform a
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
450 /// vacuum / repack operation
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
451 fn fill_nodemap(
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
452 &self,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
453 py: Python,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
454 nt: &mut NodeTree,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
455 ) -> PyResult<PyObject> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
456 let index = self.cindex(py).borrow();
51214
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51213
diff changeset
457 for r in 0..self.len(py)? {
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
458 let rev = Revision(r as BaseRevision);
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
459 // in this case node() won't ever return None
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
460 nt.insert(&*index, index.node(rev).unwrap(), rev)
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
461 .map_err(|e| nodemap_error(py, e))?
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
462 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
463 Ok(py.None())
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
464 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
465
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
466 fn get_nodetree<'a>(
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
467 &'a self,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
468 py: Python<'a>,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
469 ) -> PyResult<&'a RefCell<Option<NodeTree>>> {
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
470 if self.nt(py).borrow().is_none() {
51118
532e74ad3ff6 rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50990
diff changeset
471 let readonly = Box::<Vec<_>>::default();
44517
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
472 let mut nt = NodeTree::load_bytes(readonly, 0);
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
473 self.fill_nodemap(py, &mut nt)?;
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
474 self.nt(py).borrow_mut().replace(nt);
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
475 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
476 Ok(self.nt(py))
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
477 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44516
diff changeset
478
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
479 /// forward a method call to the underlying C index
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
480 fn call_cindex(
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
481 &self,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
482 py: Python,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
483 name: &str,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
484 args: &PyTuple,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
485 kwargs: Option<&PyDict>,
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
486 ) -> PyResult<PyObject> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
487 self.cindex(py)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
488 .borrow()
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
489 .inner()
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
490 .call_method(py, name, args, kwargs)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
491 }
44013
2728fcb8127c rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43966
diff changeset
492
2728fcb8127c rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43966
diff changeset
493 pub fn clone_cindex(&self, py: Python) -> cindex::Index {
2728fcb8127c rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43966
diff changeset
494 self.cindex(py).borrow().clone_ref(py)
2728fcb8127c rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43966
diff changeset
495 }
44518
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
496
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
497 /// Returns the full nodemap bytes to be written as-is to disk
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
498 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
499 let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap();
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
500 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes();
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
501
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
502 // If there's anything readonly, we need to build the data again from
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
503 // scratch
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
504 let bytes = if readonly.len() > 0 {
51118
532e74ad3ff6 rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50990
diff changeset
505 let mut nt = NodeTree::load_bytes(Box::<Vec<_>>::default(), 0);
44518
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
506 self.fill_nodemap(py, &mut nt)?;
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
507
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
508 let (readonly, bytes) = nt.into_readonly_and_added_bytes();
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
509 assert_eq!(readonly.len(), 0);
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
510
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
511 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
512 } else {
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
513 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
514 };
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
515
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
516 let bytes = PyBytes::new(py, &bytes);
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
517 Ok(bytes)
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44517
diff changeset
518 }
44519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
519
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
520 /// Returns the last saved docket along with the size of any changed data
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
521 /// (in number of blocks), and said data as bytes.
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
522 fn inner_nodemap_data_incremental(
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
523 &self,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
524 py: Python,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
525 ) -> PyResult<PyObject> {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
526 let docket = self.docket(py).borrow();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
527 let docket = match docket.as_ref() {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
528 Some(d) => d,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
529 None => return Ok(py.None()),
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
530 };
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
531
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
532 let node_tree = self.get_nodetree(py)?.borrow_mut().take().unwrap();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
533 let masked_blocks = node_tree.masked_readonly_blocks();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
534 let (_, data) = node_tree.into_readonly_and_added_bytes();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
535 let changed = masked_blocks * std::mem::size_of::<Block>();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
536
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
537 Ok((docket, changed, PyBytes::new(py, &data))
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
538 .to_py_object(py)
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
539 .into_object())
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44518
diff changeset
540 }
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
541
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
542 /// Update the nodemap from the new (mmaped) data.
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
543 /// The docket is kept as a reference for later incremental calls.
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
544 fn inner_update_nodemap_data(
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
545 &self,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
546 py: Python,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
547 docket: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
548 nm_data: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
549 ) -> PyResult<PyObject> {
51208
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
550 // Safety: we keep the buffer around inside the class as `nodemap_mmap`
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
551 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? };
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
552 let len = buf.item_count();
51207
8ade5e6cdb61 rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51118
diff changeset
553 self.nodemap_mmap(py).borrow_mut().replace(buf);
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
554
51208
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51207
diff changeset
555 let mut nt = NodeTree::load_bytes(bytes, len);
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
556
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
557 let data_tip = docket
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
558 .getattr(py, "tip_rev")?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
559 .extract::<BaseRevision>(py)?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
560 .into();
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
561 self.docket(py).borrow_mut().replace(docket.clone_ref(py));
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
562 let idx = self.cindex(py).borrow();
50988
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
563 let data_tip = idx.check_revision(data_tip).ok_or_else(|| {
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
564 nodemap_error(py, NodeMapError::RevisionNotInIndex(data_tip))
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
565 })?;
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
566 let current_tip = idx.len();
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
567
50990
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
568 for r in (data_tip.0 + 1)..current_tip as BaseRevision {
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50988
diff changeset
569 let rev = Revision(r);
44520
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
570 // in this case node() won't ever return None
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
571 nt.insert(&*idx, idx.node(rev).unwrap(), rev)
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
572 .map_err(|e| nodemap_error(py, e))?
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
573 }
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
574
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
575 *self.nt(py).borrow_mut() = Some(nt);
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
576
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
577 Ok(py.None())
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44519
diff changeset
578 }
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
579 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
580
44516
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
581 fn revlog_error(py: Python) -> PyErr {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
582 match py
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
583 .import("mercurial.error")
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
584 .and_then(|m| m.get(py, "RevlogError"))
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
585 {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
586 Err(e) => e,
47316
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47279
diff changeset
587 Ok(cls) => PyErr::from_instance(
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47279
diff changeset
588 py,
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47279
diff changeset
589 cls.call(py, (py.None(),), None).ok().into_py_object(py),
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47279
diff changeset
590 ),
44516
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
591 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
592 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
593
50988
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49987
diff changeset
594 fn rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr {
44516
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
595 PyErr::new::<ValueError, _>(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
596 py,
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
597 format!(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
598 "Inconsistency: Revision {} found in nodemap \
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
599 is not in revlog index",
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
600 rev
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
601 ),
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
602 )
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
603 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
604
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
605 /// Standard treatment of NodeMapError
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
606 fn nodemap_error(py: Python, err: NodeMapError) -> PyErr {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
607 match err {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
608 NodeMapError::MultipleResults => revlog_error(py),
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
609 NodeMapError::RevisionNotInIndex(r) => rev_not_in_index(py, r),
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
610 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
611 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44513
diff changeset
612
43966
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
613 /// Create the module, with __package__ given from parent
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
614 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
615 let dotted_name = &format!("{}.revlog", package);
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
616 let m = PyModule::new(py, dotted_name)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
617 m.add(py, "__package__", package)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
618 m.add(py, "__doc__", "RevLog - Rust implementations")?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
619
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
620 m.add_class::<MixedIndex>(py)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
621
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
622 let sys = PyModule::import(py, "sys")?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
623 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
624 sys_modules.set_item(py, dotted_name, &m)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
625
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
626 Ok(m)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43951
diff changeset
627 }