Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/revlog.rs @ 51209:9b06e7f32bc5
rust-index: add support for `find_snapshots`
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 03 Aug 2023 15:01:34 +0200 |
parents | b8c89957a6b7 |
children | 62e39bef36ca |
rev | line source |
---|---|
43945
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 // |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
3 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net> |
43945
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 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
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:
44506
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:
44506
diff
changeset
|
10 utils::{node_from_py_bytes, node_from_py_object}, |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
11 PyRevision, |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
12 }; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
13 use cpython::{ |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
14 buffer::{Element, PyBuffer}, |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
15 exc::{IndexError, ValueError}, |
51198
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
16 ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule, |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
17 PyObject, PyResult, PySet, PyString, PyTuple, Python, PythonObject, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
18 ToPyObject, |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
19 }; |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
20 use hg::{ |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
21 errors::HgError, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
22 index::{IndexHeader, RevisionDataParams, SnapshotsCache}, |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
23 nodemap::{Block, NodeMapError, NodeTree}, |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
24 revlog::{nodemap::NodeMap, NodePrefix, RevlogError, RevlogIndex}, |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
25 BaseRevision, Revision, UncheckedRevision, NULL_REVISION, |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
26 }; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
27 use std::cell::RefCell; |
43945
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 |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 /// Return a Struct implementing the Graph trait |
44070
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44012
diff
changeset
|
30 pub(crate) fn pyindex_to_graph( |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44012
diff
changeset
|
31 py: Python, |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44012
diff
changeset
|
32 index: PyObject, |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44012
diff
changeset
|
33 ) -> PyResult<cindex::Index> { |
44011
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44010
diff
changeset
|
34 match index.extract::<MixedIndex>(py) { |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44010
diff
changeset
|
35 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:
44010
diff
changeset
|
36 Err(_) => cindex::Index::new(py, index), |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44010
diff
changeset
|
37 } |
43945
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 } |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
39 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
40 py_class!(pub class MixedIndex |py| { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
41 data cindex: RefCell<cindex::Index>; |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
42 data index: RefCell<hg::index::Index>; |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
43 data nt: RefCell<Option<NodeTree>>; |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
44 data docket: RefCell<Option<PyObject>>; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
45 // Holds a reference to the mmap'ed persistent nodemap data |
51183
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
46 data nodemap_mmap: RefCell<Option<PyBuffer>>; |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
47 // 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:
51184
diff
changeset
|
48 data index_mmap: RefCell<Option<PyBuffer>>; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
49 |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
50 def __new__( |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
51 _cls, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
52 cindex: PyObject, |
51188
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
53 data: PyObject, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
54 default_header: u32, |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
55 ) -> PyResult<MixedIndex> { |
51188
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
56 Self::new(py, cindex, data, default_header) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
57 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
58 |
44012
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
59 /// 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:
44011
diff
changeset
|
60 /// |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
61 /// 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:
44011
diff
changeset
|
62 /// 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:
44011
diff
changeset
|
63 /// 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:
44011
diff
changeset
|
64 /// 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:
44011
diff
changeset
|
65 /// ready to accept `MixedIndex`. |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
66 def get_cindex(&self) -> PyResult<PyObject> { |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
67 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:
44011
diff
changeset
|
68 } |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
69 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
70 // Index API involving nodemap, as defined in mercurial/pure/parsers.py |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
71 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
72 /// 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:
44506
diff
changeset
|
73 /// in case of ambiguity, same as C version does |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
74 def get_rev(&self, node: PyBytes) -> PyResult<Option<PyRevision>> { |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
75 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:
44506
diff
changeset
|
76 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:
44506
diff
changeset
|
77 let idx = &*self.cindex(py).borrow(); |
51193
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
78 let ridx = &*self.index(py).borrow(); |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
79 let node = node_from_py_bytes(py, &node)?; |
51193
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
80 let rust_rev = |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
81 nt.find_bin(ridx, node.into()).map_err(|e| nodemap_error(py, e))?; |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
82 let c_rev = |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
83 nt.find_bin(idx, node.into()).map_err(|e| nodemap_error(py, e))?; |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
84 assert_eq!(rust_rev, c_rev); |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
85 Ok(rust_rev.map(Into::into)) |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
86 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
87 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
88 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
89 /// 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:
44506
diff
changeset
|
90 /// is not found. |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
91 /// |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
92 /// 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:
44506
diff
changeset
|
93 /// will catch and rewrap with it |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
94 def rev(&self, node: PyBytes) -> PyResult<PyRevision> { |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
95 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:
44506
diff
changeset
|
96 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
97 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
98 /// 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:
44506
diff
changeset
|
99 def has_node(&self, node: PyBytes) -> PyResult<bool> { |
51201
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
100 // TODO OPTIM we could avoid a needless conversion here, |
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
101 // to do when scaffolding for pure Rust switch is removed, |
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
102 // as `get_rev()` currently does the necessary assertions |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
103 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:
44506
diff
changeset
|
104 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
105 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
106 /// 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:
44506
diff
changeset
|
107 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:
44506
diff
changeset
|
108 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:
44506
diff
changeset
|
109 let nt = opt.as_ref().unwrap(); |
51205
274abd1562a2
rust-index: use the rust index in `shortest`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51204
diff
changeset
|
110 let idx = &*self.index(py).borrow(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
111 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:
44506
diff
changeset
|
112 { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
113 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:
44506
diff
changeset
|
114 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:
44506
diff
changeset
|
115 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:
44506
diff
changeset
|
116 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
117 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
118 |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
119 def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> { |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
120 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:
44506
diff
changeset
|
121 let nt = opt.as_ref().unwrap(); |
51207
72d16685d63a
rust-index: use the Rust index in `partialmatch`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51205
diff
changeset
|
122 let idx = &*self.index(py).borrow(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
123 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
124 let node_as_string = if cfg!(feature = "python3-sys") { |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
125 node.cast_as::<PyString>(py)?.to_string(py)?.to_string() |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
126 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
127 else { |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
128 let node = node.extract::<PyBytes>(py)?; |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
129 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:
44506
diff
changeset
|
130 }; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
131 |
49374
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
132 let prefix = NodePrefix::from_hex(&node_as_string) |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
133 .map_err(|_| PyErr::new::<ValueError, _>( |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
134 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:
48269
diff
changeset
|
135 )?; |
46432
18a261b11b20
rust: Remove hex parsing from the nodemap
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
136 |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
137 nt.find_bin(idx, prefix) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
138 // 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:
47799
diff
changeset
|
139 .map(|opt| opt.map( |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
140 |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:
47799
diff
changeset
|
141 .map_err(|e| nodemap_error(py, e)) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
142 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
143 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
144 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
145 /// 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:
44506
diff
changeset
|
146 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:
44506
diff
changeset
|
147 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:
44506
diff
changeset
|
148 // 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:
44506
diff
changeset
|
149 return Err( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
150 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:
44506
diff
changeset
|
151 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
152 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:
44506
diff
changeset
|
153 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:
44506
diff
changeset
|
154 |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
155 let rev = self.len(py)? as BaseRevision; |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
156 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:
44506
diff
changeset
|
157 |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
158 // This is ok since we will just add the revision to the index |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
159 let rev = Revision(rev); |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
160 idx.append(py, tup.clone_ref(py))?; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
161 self.index(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
162 .borrow_mut() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
163 .append(py_tuple_to_revision_data_params(py, tup)?) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
164 .unwrap(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
165 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:
44506
diff
changeset
|
166 .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:
44506
diff
changeset
|
167 .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:
44506
diff
changeset
|
168 Ok(py.None()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
169 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
170 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
171 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:
44506
diff
changeset
|
172 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]` |
51192
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
173 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:
51191
diff
changeset
|
174 let start = key.getattr(py, "start")?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
175 let start = UncheckedRevision(start.extract(py)?); |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
176 let start = self.index(py) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
177 .borrow() |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
178 .check_revision(start) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
179 .ok_or_else(|| { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
180 nodemap_error(py, NodeMapError::RevisionNotInIndex(start)) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
181 })?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
182 self.index(py).borrow_mut().remove(start).unwrap(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
183 let mut opt = self.get_nodetree(py)?.borrow_mut(); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49374
diff
changeset
|
184 let nt = opt.as_mut().unwrap(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
185 nt.invalidate_all(); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49374
diff
changeset
|
186 self.fill_nodemap(py, nt)?; |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
187 Ok(()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
188 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
189 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
190 // |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
191 // Reforwarded C index API |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
192 // |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
193 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
194 // 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:
43945
diff
changeset
|
195 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
196 /// 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:
43945
diff
changeset
|
197 def ancestors(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
198 self.call_cindex(py, "ancestors", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
199 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
200 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
201 /// 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:
43945
diff
changeset
|
202 def commonancestorsheads(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
203 self.call_cindex(py, "commonancestorsheads", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
204 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
205 |
44511
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
206 /// 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:
44510
diff
changeset
|
207 /// It is Python's responsibility to call `update_nodemap_data` again. |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
208 def clearcaches(&self, *args, **kw) -> PyResult<PyObject> { |
44511
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
209 self.nt(py).borrow_mut().take(); |
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
210 self.docket(py).borrow_mut().take(); |
51183
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
211 self.nodemap_mmap(py).borrow_mut().take(); |
51194
4e6620b7fbbb
rust-index: support cache clearing
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51193
diff
changeset
|
212 self.index(py).borrow_mut().clear_caches(); |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
213 self.call_cindex(py, "clearcaches", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
214 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
215 |
47034
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
216 /// 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
|
217 def entry_binary(&self, *args, **kw) -> PyResult<PyObject> { |
51200
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
218 let rindex = self.index(py).borrow(); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
219 let rev = UncheckedRevision(args.get_item(py, 0).extract(py)?); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
220 let rust_bytes = rindex.check_revision(rev).and_then( |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
221 |r| rindex.entry_binary(r)) |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
222 .ok_or_else(|| rev_not_in_index(py, rev))?; |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
223 let rust_res = PyBytes::new(py, rust_bytes).into_object(); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
224 |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
225 let c_res = self.call_cindex(py, "entry_binary", args, kw)?; |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
226 assert_py_eq(py, "entry_binary", &rust_res, &c_res)?; |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
227 Ok(rust_res) |
47034
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
228 } |
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
229 |
47037
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
230 /// 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:
47034
diff
changeset
|
231 def pack_header(&self, *args, **kw) -> PyResult<PyObject> { |
51195
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51194
diff
changeset
|
232 let rindex = self.index(py).borrow(); |
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51194
diff
changeset
|
233 let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); |
51199
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
234 let rust_res = PyBytes::new(py, &packed).into_object(); |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
235 |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
236 let c_res = self.call_cindex(py, "pack_header", args, kw)?; |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
237 assert_py_eq(py, "pack_header", &rust_res, &c_res)?; |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
238 Ok(rust_res) |
47037
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
239 } |
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
240 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
241 /// compute phases |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
242 def computephasesmapsets(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
243 self.call_cindex(py, "computephasesmapsets", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
244 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
245 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
246 /// reachableroots |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
247 def reachableroots2(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
248 self.call_cindex(py, "reachableroots2", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
249 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
250 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
251 /// get head revisions |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
252 def headrevs(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
253 self.call_cindex(py, "headrevs", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
254 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
255 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
256 /// get filtered head revisions |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
257 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
258 self.call_cindex(py, "headrevsfiltered", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
259 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
260 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
261 /// True if the object is a snapshot |
51208
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
262 def issnapshot(&self, *args, **kw) -> PyResult<bool> { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
263 let index = self.index(py).borrow(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
264 let result = index |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
265 .is_snapshot(UncheckedRevision(args.get_item(py, 0).extract(py)?)) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
266 .map_err(|e| { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
267 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
268 })?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
269 let cresult = self.call_cindex(py, "issnapshot", args, kw)?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
270 assert_eq!(result, cresult.extract(py)?); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
271 Ok(result) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
272 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
273 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
274 /// Gather snapshot data in a cache dict |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
275 def findsnapshots(&self, *args, **kw) -> PyResult<PyObject> { |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
276 let index = self.index(py).borrow(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
277 let cache: PyDict = args.get_item(py, 0).extract(py)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
278 // this methods operates by setting new values in the cache, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
279 // hence we will compare results by letting the C implementation |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
280 // operate over a deepcopy of the cache, and finally compare both |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
281 // caches. |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
282 let c_cache = PyDict::new(py); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
283 for (k, v) in cache.items(py) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
284 c_cache.set_item(py, k, PySet::new(py, v)?)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
285 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
286 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
287 let start_rev = UncheckedRevision(args.get_item(py, 1).extract(py)?); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
288 let end_rev = UncheckedRevision(args.get_item(py, 2).extract(py)?); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
289 let mut cache_wrapper = PySnapshotsCache{ py, dict: cache }; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
290 index.find_snapshots( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
291 start_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
292 end_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
293 &mut cache_wrapper, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
294 ).map_err(|_| revlog_error(py))?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
295 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
296 let c_args = PyTuple::new( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
297 py, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
298 &[ |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
299 c_cache.clone_ref(py).into_object(), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
300 args.get_item(py, 1), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
301 args.get_item(py, 2) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
302 ] |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
303 ); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
304 self.call_cindex(py, "findsnapshots", &c_args, kw)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
305 assert_py_eq(py, "findsnapshots cache", |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
306 &cache_wrapper.into_object(), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
307 &c_cache.into_object())?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
308 Ok(py.None()) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
309 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
310 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
311 /// determine revisions with deltas to reconstruct fulltext |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
312 def deltachain(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
313 self.call_cindex(py, "deltachain", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
314 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
315 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
316 /// 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:
43945
diff
changeset
|
317 def slicechunktodensity(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
318 self.call_cindex(py, "slicechunktodensity", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
319 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
320 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
321 /// stats for the index |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
322 def stats(&self, *args, **kw) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
323 self.call_cindex(py, "stats", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
324 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
325 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
326 // index_sequence_methods and index_mapping_methods. |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
327 // |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
328 // 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:
43945
diff
changeset
|
329 // 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:
43945
diff
changeset
|
330 // and index_getitem. |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
331 // gracinet 2023: this above is no longer true for the pure Rust impl |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
332 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
333 def __len__(&self) -> PyResult<usize> { |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
334 self.len(py) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
335 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
336 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
337 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
338 let rust_res = self.inner_getitem(py, key.clone_ref(py))?; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
339 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
340 // 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:
43945
diff
changeset
|
341 // `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:
43945
diff
changeset
|
342 // 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:
43945
diff
changeset
|
343 // Note that we don't seem to have a direct way to call |
44511
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
344 // PySequence_GetItem (does the job), which would possibly be better |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
345 // for performance |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
346 // gracinet 2023: the above comment can be removed when we use |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
347 // the pure Rust impl only. Note also that `key` can be a binary |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
348 // node id. |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
349 let c_key = match key.extract::<BaseRevision>(py) { |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
350 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:
43945
diff
changeset
|
351 Err(_) => key, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
352 }; |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
353 let c_res = self.cindex(py).borrow().inner().get_item(py, c_key)?; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
354 |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
355 assert_py_eq(py, "__getitem__", &rust_res, &c_res)?; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
356 Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
357 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
358 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
359 def __contains__(&self, item: PyObject) -> PyResult<bool> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
360 // 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:
43945
diff
changeset
|
361 // 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:
43945
diff
changeset
|
362 // defined in revlog.c |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
363 let cindex = self.cindex(py).borrow(); |
50974
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49914
diff
changeset
|
364 match item.extract::<i32>(py) { |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
365 Ok(rev) => { |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
366 Ok(rev >= -1 && rev < self.len(py)? as BaseRevision) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
367 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
368 Err(_) => { |
51204
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
369 let item_bytes: PyBytes = item.extract(py)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
370 let rust_res = self.has_node(py, item_bytes)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
371 |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
372 let c_res = cindex.inner().call_method( |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
373 py, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
374 "has_node", |
51204
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
375 PyTuple::new(py, &[item.clone_ref(py)]), |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
376 None)? |
51204
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
377 .extract(py)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
378 |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
379 assert_eq!(rust_res, c_res); |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
380 Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
381 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
382 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
383 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
384 |
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
385 def nodemap_data_all(&self) -> PyResult<PyBytes> { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
386 self.inner_nodemap_data_all(py) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
387 } |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
388 |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
389 def nodemap_data_incremental(&self) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
390 self.inner_nodemap_data_incremental(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
391 } |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
392 def update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
393 &self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
394 docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
395 nm_data: PyObject |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
396 ) -> PyResult<PyObject> { |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
397 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:
44509
diff
changeset
|
398 } |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
399 |
46974
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46432
diff
changeset
|
400 @property |
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46432
diff
changeset
|
401 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:
46432
diff
changeset
|
402 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:
46432
diff
changeset
|
403 } |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
404 |
47268
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
405 @property |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
406 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:
47037
diff
changeset
|
407 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:
47037
diff
changeset
|
408 } |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
409 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
410 }); |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
411 |
51184
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
412 /// 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:
51183
diff
changeset
|
413 /// 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:
51183
diff
changeset
|
414 /// 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:
51183
diff
changeset
|
415 /// 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:
51183
diff
changeset
|
416 /// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
417 /// # Safety |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
418 /// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
419 /// 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:
51183
diff
changeset
|
420 /// long as the slice. |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
421 #[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:
51183
diff
changeset
|
422 unsafe fn mmap_keeparound( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
423 py: Python, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
424 data: PyObject, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
425 ) -> PyResult<( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
426 PyBuffer, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
427 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:
51183
diff
changeset
|
428 )> { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
429 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:
51183
diff
changeset
|
430 let len = buf.item_count(); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
431 |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
432 // 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:
51183
diff
changeset
|
433 let cbuf = buf.buf_ptr(); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
434 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:
51183
diff
changeset
|
435 && buf.is_c_contiguous() |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
436 && 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:
51183
diff
changeset
|
437 { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
438 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:
51183
diff
changeset
|
439 } else { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
440 return Err(PyErr::new::<ValueError, _>( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
441 py, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
442 "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:
51183
diff
changeset
|
443 .to_string(), |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
444 )); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
445 }; |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
446 |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
447 Ok((buf, Box::new(bytes))) |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
448 } |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
449 |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
450 fn py_tuple_to_revision_data_params( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
451 py: Python, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
452 tuple: PyTuple, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
453 ) -> PyResult<RevisionDataParams> { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
454 if tuple.len(py) < 8 { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
455 // 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:
51188
diff
changeset
|
456 return Err(PyErr::new::<IndexError, _>( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
457 py, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
458 "tuple index out of range", |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
459 )); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
460 } |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
461 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:
51188
diff
changeset
|
462 let node_id = tuple |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
463 .get_item(py, 7) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
464 .extract::<PyBytes>(py)? |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
465 .data(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
466 .try_into() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
467 .unwrap(); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
468 let flags = (offset_or_flags & 0xFFFF) as u16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
469 let data_offset = offset_or_flags >> 16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
470 Ok(RevisionDataParams { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
471 flags, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
472 data_offset, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
473 data_compressed_length: tuple.get_item(py, 1).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
474 data_uncompressed_length: tuple.get_item(py, 2).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
475 data_delta_base: tuple.get_item(py, 3).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
476 link_rev: tuple.get_item(py, 4).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
477 parent_rev_1: tuple.get_item(py, 5).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
478 parent_rev_2: tuple.get_item(py, 6).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
479 node_id, |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
480 ..Default::default() |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
481 }) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
482 } |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
483 fn revision_data_params_to_py_tuple( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
484 py: Python, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
485 params: RevisionDataParams, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
486 ) -> PyTuple { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
487 PyTuple::new( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
488 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
489 &[ |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
490 params.data_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
491 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
492 .data_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
493 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
494 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
495 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
496 .data_uncompressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
497 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
498 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
499 params.data_delta_base.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
500 params.link_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
501 params.parent_rev_1.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
502 params.parent_rev_2.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
503 PyBytes::new(py, ¶ms.node_id) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
504 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
505 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
506 params._sidedata_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
507 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
508 ._sidedata_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
509 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
510 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
511 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
512 .data_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
513 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
514 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
515 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
516 ._sidedata_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
517 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
518 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
519 params._rank.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
520 ], |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
521 ) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
522 } |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
523 |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
524 struct PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
525 py: Python<'p>, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
526 dict: PyDict, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
527 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
528 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
529 impl<'p> PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
530 fn into_object(self) -> PyObject { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
531 self.dict.into_object() |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
532 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
533 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
534 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
535 impl<'p> SnapshotsCache for PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
536 fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
537 &mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
538 rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
539 value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
540 ) -> Result<(), RevlogError> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
541 let pyvalue = value.into_py_object(self.py).into_object(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
542 match self.dict.get_item(self.py, rev) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
543 Some(obj) => obj |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
544 .extract::<PySet>(self.py) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
545 .and_then(|set| set.add(self.py, pyvalue)), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
546 None => PySet::new(self.py, vec![pyvalue]) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
547 .and_then(|set| self.dict.set_item(self.py, rev, set)), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
548 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
549 .map_err(|_| { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
550 RevlogError::Other(HgError::unsupported( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
551 "Error in Python caches handling", |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
552 )) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
553 }) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
554 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
555 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
556 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
557 impl MixedIndex { |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
558 fn new( |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
559 py: Python, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
560 cindex: PyObject, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
561 data: PyObject, |
51188
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
562 header: u32, |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
563 ) -> PyResult<MixedIndex> { |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
564 // 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:
51184
diff
changeset
|
565 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:
51184
diff
changeset
|
566 |
44503
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
567 Self::create_instance( |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
568 py, |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
569 RefCell::new(cindex::Index::new(py, cindex)?), |
51188
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
570 RefCell::new( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
571 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:
51187
diff
changeset
|
572 bytes, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
573 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:
51187
diff
changeset
|
574 .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:
51187
diff
changeset
|
575 .unwrap(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
576 ) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
577 .unwrap(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
578 ), |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
579 RefCell::new(None), |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
580 RefCell::new(None), |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
581 RefCell::new(None), |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
582 RefCell::new(Some(buf)), |
44503
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
583 ) |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
584 } |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
585 |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
586 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:
51189
diff
changeset
|
587 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:
51189
diff
changeset
|
588 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:
51189
diff
changeset
|
589 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:
51189
diff
changeset
|
590 Ok(cindex_len) |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
591 } |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
592 |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
593 /// 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:
44506
diff
changeset
|
594 /// 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:
44506
diff
changeset
|
595 /// vacuum / repack operation |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
596 fn fill_nodemap( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
597 &self, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
598 py: Python, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
599 nt: &mut NodeTree, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
600 ) -> PyResult<PyObject> { |
51203
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51202
diff
changeset
|
601 let index = self.index(py).borrow(); |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
602 for r in 0..self.len(py)? { |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
603 let rev = Revision(r as BaseRevision); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
604 // 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:
44506
diff
changeset
|
605 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:
44506
diff
changeset
|
606 .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:
44506
diff
changeset
|
607 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
608 Ok(py.None()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
609 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
610 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
611 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:
44506
diff
changeset
|
612 &'a self, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
613 py: Python<'a>, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
614 ) -> 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:
44506
diff
changeset
|
615 if self.nt(py).borrow().is_none() { |
51117
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50976
diff
changeset
|
616 let readonly = Box::<Vec<_>>::default(); |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
617 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:
44506
diff
changeset
|
618 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:
44506
diff
changeset
|
619 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:
44506
diff
changeset
|
620 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
621 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:
44506
diff
changeset
|
622 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
623 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
624 /// 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:
43945
diff
changeset
|
625 fn call_cindex( |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
626 &self, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
627 py: Python, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
628 name: &str, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
629 args: &PyTuple, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
630 kwargs: Option<&PyDict>, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
631 ) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
632 self.cindex(py) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
633 .borrow() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
634 .inner() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
635 .call_method(py, name, args, kwargs) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
636 } |
44010
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43961
diff
changeset
|
637 |
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43961
diff
changeset
|
638 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:
43961
diff
changeset
|
639 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:
43961
diff
changeset
|
640 } |
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
641 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
642 /// 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:
44507
diff
changeset
|
643 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:
44507
diff
changeset
|
644 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:
44507
diff
changeset
|
645 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:
44507
diff
changeset
|
646 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
647 // 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:
44507
diff
changeset
|
648 // scratch |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
649 let bytes = if readonly.len() > 0 { |
51117
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50976
diff
changeset
|
650 let mut nt = NodeTree::load_bytes(Box::<Vec<_>>::default(), 0); |
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
651 self.fill_nodemap(py, &mut nt)?; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
652 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
653 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:
44507
diff
changeset
|
654 assert_eq!(readonly.len(), 0); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
655 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
656 bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
657 } else { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
658 bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
659 }; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
660 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
661 let bytes = PyBytes::new(py, &bytes); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
662 Ok(bytes) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
663 } |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
664 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
665 /// 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:
44508
diff
changeset
|
666 /// (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:
44508
diff
changeset
|
667 fn inner_nodemap_data_incremental( |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
668 &self, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
669 py: Python, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
670 ) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
671 let docket = self.docket(py).borrow(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
672 let docket = match docket.as_ref() { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
673 Some(d) => d, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
674 None => return Ok(py.None()), |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
675 }; |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
676 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
677 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:
44508
diff
changeset
|
678 let masked_blocks = node_tree.masked_readonly_blocks(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
679 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:
44508
diff
changeset
|
680 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:
44508
diff
changeset
|
681 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
682 Ok((docket, changed, PyBytes::new(py, &data)) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
683 .to_py_object(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
684 .into_object()) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
685 } |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
686 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
687 /// Update the nodemap from the new (mmaped) data. |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
688 /// 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:
44509
diff
changeset
|
689 fn inner_update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
690 &self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
691 py: Python, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
692 docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
693 nm_data: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
694 ) -> PyResult<PyObject> { |
51184
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
695 // 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:
51183
diff
changeset
|
696 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? }; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
697 let len = buf.item_count(); |
51183
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
698 self.nodemap_mmap(py).borrow_mut().replace(buf); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
699 |
51184
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
700 let mut nt = NodeTree::load_bytes(bytes, len); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
701 |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
702 let data_tip = docket |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
703 .getattr(py, "tip_rev")? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
704 .extract::<BaseRevision>(py)? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
705 .into(); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
706 self.docket(py).borrow_mut().replace(docket.clone_ref(py)); |
51203
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51202
diff
changeset
|
707 let idx = self.index(py).borrow(); |
50974
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49914
diff
changeset
|
708 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:
49914
diff
changeset
|
709 nodemap_error(py, NodeMapError::RevisionNotInIndex(data_tip)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49914
diff
changeset
|
710 })?; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
711 let current_tip = idx.len(); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
712 |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
713 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:
50974
diff
changeset
|
714 let rev = Revision(r); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
715 // 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:
44509
diff
changeset
|
716 nt.insert(&*idx, idx.node(rev).unwrap(), rev) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
717 .map_err(|e| nodemap_error(py, e))? |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
718 } |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
719 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
720 *self.nt(py).borrow_mut() = Some(nt); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
721 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
722 Ok(py.None()) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
723 } |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
724 |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
725 fn inner_getitem(&self, py: Python, key: PyObject) -> PyResult<PyObject> { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
726 let idx = self.index(py).borrow(); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
727 Ok(match key.extract::<BaseRevision>(py) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
728 Ok(key_as_int) => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
729 let entry_params = if key_as_int == NULL_REVISION.0 { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
730 RevisionDataParams::default() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
731 } else { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
732 let rev = UncheckedRevision(key_as_int); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
733 match idx.entry_as_params(rev) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
734 Some(e) => e, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
735 None => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
736 return Err(PyErr::new::<IndexError, _>( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
737 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
738 "revlog index out of range", |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
739 )); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
740 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
741 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
742 }; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
743 revision_data_params_to_py_tuple(py, entry_params) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
744 .into_object() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
745 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
746 _ => self.get_rev(py, key.extract::<PyBytes>(py)?)?.map_or_else( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
747 || py.None(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
748 |py_rev| py_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
749 ), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
750 }) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
751 } |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
752 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
753 |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
754 fn revlog_error(py: Python) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
755 match py |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
756 .import("mercurial.error") |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
757 .and_then(|m| m.get(py, "RevlogError")) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
758 { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
759 Err(e) => e, |
47305
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
760 Ok(cls) => PyErr::from_instance( |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
761 py, |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
762 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:
47268
diff
changeset
|
763 ), |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
764 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
765 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
766 |
51196
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51195
diff
changeset
|
767 fn nodemap_rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr { |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
768 PyErr::new::<ValueError, _>( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
769 py, |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
770 format!( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
771 "Inconsistency: Revision {} found in nodemap \ |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
772 is not in revlog index", |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
773 rev |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
774 ), |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
775 ) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
776 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
777 |
51197
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
778 fn rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr { |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
779 PyErr::new::<ValueError, _>( |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
780 py, |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
781 format!("revlog index out of range: {}", rev), |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
782 ) |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
783 } |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
784 |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
785 /// Standard treatment of NodeMapError |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
786 fn nodemap_error(py: Python, err: NodeMapError) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
787 match err { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
788 NodeMapError::MultipleResults => revlog_error(py), |
51196
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51195
diff
changeset
|
789 NodeMapError::RevisionNotInIndex(r) => nodemap_rev_not_in_index(py, r), |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
790 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
791 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
792 |
51198
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
793 fn assert_py_eq( |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
794 py: Python, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
795 method: &str, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
796 rust: &PyObject, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
797 c: &PyObject, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
798 ) -> PyResult<()> { |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
799 let locals = PyDict::new(py); |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
800 locals.set_item(py, "rust".into_py_object(py).into_object(), rust)?; |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
801 locals.set_item(py, "c".into_py_object(py).into_object(), c)?; |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
802 let is_eq: PyBool = |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
803 py.eval("rust == c", None, Some(&locals))?.extract(py)?; |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
804 assert!( |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
805 is_eq.is_true(), |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
806 "{} results differ. Rust: {:?} C: {:?}", |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
807 method, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
808 rust, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
809 c |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
810 ); |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
811 Ok(()) |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
812 } |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51197
diff
changeset
|
813 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
814 /// 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:
43945
diff
changeset
|
815 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:
43945
diff
changeset
|
816 let dotted_name = &format!("{}.revlog", package); |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
817 let m = PyModule::new(py, dotted_name)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
818 m.add(py, "__package__", package)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
819 m.add(py, "__doc__", "RevLog - Rust implementations")?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
820 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
821 m.add_class::<MixedIndex>(py)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
822 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
823 let sys = PyModule::import(py, "sys")?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
824 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:
43945
diff
changeset
|
825 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:
43945
diff
changeset
|
826 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
827 Ok(m) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
828 } |