Mercurial > public > mercurial-scm > hg-stable
annotate rust/hg-cpython/src/revlog.rs @ 51253:3551f2a1c963
debugindexstats: handle the lack of Rust support better
We don't have any stats in the Rust index. Currently it is not known which
stats would be interesting to get, so if they end up being important, we can
add them later.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 31 Oct 2023 18:09:43 +0100 |
parents | 5807e3a8865e |
children | ca81cd96000a |
rev | line source |
---|---|
43951
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 // revlog.rs |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 // |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
3 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net> |
43951
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 // |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
8 use crate::{ |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
9 cindex, |
51243
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
10 conversion::{rev_pyiter_collect, rev_pyiter_collect_or_else}, |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
11 utils::{node_from_py_bytes, node_from_py_object}, |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
12 PyRevision, |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
13 }; |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
14 use cpython::{ |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
15 buffer::{Element, PyBuffer}, |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
16 exc::{IndexError, ValueError}, |
51236
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
17 ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, PyList, |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
18 PyModule, PyObject, PyResult, PySet, PyString, PyTuple, Python, |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
19 PythonObject, ToPyObject, |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
20 }; |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
21 use hg::{ |
51233
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
22 errors::HgError, |
51250
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
23 index::{ |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
24 IndexHeader, Phase, RevisionDataParams, SnapshotsCache, |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
25 INDEX_ENTRY_SIZE, |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
26 }, |
44519
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
27 nodemap::{Block, NodeMapError, NodeTree}, |
51233
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
28 revlog::{nodemap::NodeMap, NodePrefix, RevlogError, RevlogIndex}, |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
29 BaseRevision, Revision, UncheckedRevision, NULL_REVISION, |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
30 }; |
51241
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
31 use std::{cell::RefCell, collections::HashMap}; |
43951
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 /// Return a Struct implementing the Graph trait |
44070
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44015
diff
changeset
|
34 pub(crate) fn pyindex_to_graph( |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44015
diff
changeset
|
35 py: Python, |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44015
diff
changeset
|
36 index: PyObject, |
451d22174b5f
revlog: run rustfmt nightly
Augie Fackler <augie@google.com>
parents:
44015
diff
changeset
|
37 ) -> PyResult<cindex::Index> { |
44014
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44013
diff
changeset
|
38 match index.extract::<MixedIndex>(py) { |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44013
diff
changeset
|
39 Ok(midx) => Ok(midx.clone_cindex(py)), |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44013
diff
changeset
|
40 Err(_) => cindex::Index::new(py, index), |
c627f1b2f3c3
rust-index: handle `MixedIndex` in `pyindex_to_graph`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44013
diff
changeset
|
41 } |
43951
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 } |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
43 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
44 py_class!(pub class MixedIndex |py| { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
45 data cindex: RefCell<cindex::Index>; |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
46 data index: RefCell<hg::index::Index>; |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
47 data nt: RefCell<Option<NodeTree>>; |
44519
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
48 data docket: RefCell<Option<PyObject>>; |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
49 // Holds a reference to the mmap'ed persistent nodemap data |
51207
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51118
diff
changeset
|
50 data nodemap_mmap: RefCell<Option<PyBuffer>>; |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
51 // Holds a reference to the mmap'ed persistent index data |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
52 data index_mmap: RefCell<Option<PyBuffer>>; |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
53 |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
54 def __new__( |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
55 _cls, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
56 cindex: PyObject, |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
57 data: PyObject, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
58 default_header: u32, |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
59 ) -> PyResult<MixedIndex> { |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
60 Self::new(py, cindex, data, default_header) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
61 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
62 |
44015
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
63 /// Compatibility layer used for Python consumers needing access to the C index |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
64 /// |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
65 /// Only use case so far is `scmutil.shortesthexnodeidprefix`, |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
66 /// that may need to build a custom `nodetree`, based on a specified revset. |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
67 /// With a Rust implementation of the nodemap, we will be able to get rid of |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
68 /// this, by exposing our own standalone nodemap class, |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
69 /// ready to accept `MixedIndex`. |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
70 def get_cindex(&self) -> PyResult<PyObject> { |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
71 Ok(self.cindex(py).borrow().inner().clone_ref(py)) |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
72 } |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44014
diff
changeset
|
73 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
74 // Index API involving nodemap, as defined in mercurial/pure/parsers.py |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
75 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
76 /// Return Revision if found, raises a bare `error.RevlogError` |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
77 /// in case of ambiguity, same as C version does |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
78 def get_rev(&self, node: PyBytes) -> PyResult<Option<PyRevision>> { |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
79 let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
80 let nt = opt.as_ref().unwrap(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
81 let idx = &*self.cindex(py).borrow(); |
51217
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
82 let ridx = &*self.index(py).borrow(); |
47894
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
83 let node = node_from_py_bytes(py, &node)?; |
51217
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
84 let rust_rev = |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
85 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:
51216
diff
changeset
|
86 let c_rev = |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
87 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:
51216
diff
changeset
|
88 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:
51216
diff
changeset
|
89 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:
51216
diff
changeset
|
90 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
91 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
92 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
93 /// same as `get_rev()` but raises a bare `error.RevlogError` if node |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
94 /// is not found. |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
95 /// |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
96 /// No need to repeat `node` in the exception, `mercurial/revlog.py` |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
97 /// will catch and rewrap with it |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
98 def rev(&self, node: PyBytes) -> PyResult<PyRevision> { |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
99 self.get_rev(py, node)?.ok_or_else(|| revlog_error(py)) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
100 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
101 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
102 /// return True if the node exist in the index |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
103 def has_node(&self, node: PyBytes) -> PyResult<bool> { |
51225
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51224
diff
changeset
|
104 // 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:
51224
diff
changeset
|
105 // 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:
51224
diff
changeset
|
106 // as `get_rev()` currently does the necessary assertions |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
107 self.get_rev(py, node).map(|opt| opt.is_some()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
108 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
109 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
110 /// find length of shortest hex nodeid of a binary ID |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
111 def shortest(&self, node: PyBytes) -> PyResult<usize> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
112 let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
113 let nt = opt.as_ref().unwrap(); |
51229
274abd1562a2
rust-index: use the rust index in `shortest`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51228
diff
changeset
|
114 let idx = &*self.index(py).borrow(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
115 match nt.unique_prefix_len_node(idx, &node_from_py_bytes(py, &node)?) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
116 { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
117 Ok(Some(l)) => Ok(l), |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
118 Ok(None) => Err(revlog_error(py)), |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
119 Err(e) => Err(nodemap_error(py, e)), |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
120 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
121 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
122 |
47894
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
123 def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> { |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
124 let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
125 let nt = opt.as_ref().unwrap(); |
51231
72d16685d63a
rust-index: use the Rust index in `partialmatch`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51229
diff
changeset
|
126 let idx = &*self.index(py).borrow(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
127 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
128 let node_as_string = if cfg!(feature = "python3-sys") { |
47894
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
129 node.cast_as::<PyString>(py)?.to_string(py)?.to_string() |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
130 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
131 else { |
47894
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
132 let node = node.extract::<PyBytes>(py)?; |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
133 String::from_utf8_lossy(node.data(py)).to_string() |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
134 }; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
135 |
49373
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47894
diff
changeset
|
136 let prefix = NodePrefix::from_hex(&node_as_string) |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47894
diff
changeset
|
137 .map_err(|_| PyErr::new::<ValueError, _>( |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47894
diff
changeset
|
138 py, format!("Invalid node or prefix '{}'", node_as_string)) |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47894
diff
changeset
|
139 )?; |
46500
18a261b11b20
rust: Remove hex parsing from the nodemap
Simon Sapin <simon.sapin@octobus.net>
parents:
46499
diff
changeset
|
140 |
47894
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
141 nt.find_bin(idx, prefix) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
142 // TODO make an inner API returning the node directly |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
143 .map(|opt| opt.map( |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
144 |rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
145 .map_err(|e| nodemap_error(py, e)) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47795
diff
changeset
|
146 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
147 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
148 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
149 /// append an index entry |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
150 def append(&self, tup: PyTuple) -> PyResult<PyObject> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
151 if tup.len(py) < 8 { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
152 // this is better than the panic promised by tup.get_item() |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
153 return Err( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
154 PyErr::new::<IndexError, _>(py, "tuple index out of range")) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
155 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
156 let node_bytes = tup.get_item(py, 7).extract(py)?; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
157 let node = node_from_py_object(py, &node_bytes)?; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
158 |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
159 let rev = self.len(py)? as BaseRevision; |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
160 let mut idx = self.cindex(py).borrow_mut(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
161 |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
162 // This is ok since we will just add the revision to the index |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
163 let rev = Revision(rev); |
51213
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
164 idx.append(py, tup.clone_ref(py))?; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
165 self.index(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
166 .borrow_mut() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
167 .append(py_tuple_to_revision_data_params(py, tup)?) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
168 .unwrap(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
169 self.get_nodetree(py)?.borrow_mut().as_mut().unwrap() |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
170 .insert(&*idx, &node, rev) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
171 .map_err(|e| nodemap_error(py, e))?; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
172 Ok(py.None()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
173 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
174 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
175 def __delitem__(&self, key: PyObject) -> PyResult<()> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
176 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]` |
51216
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
177 self.cindex(py).borrow().inner().del_item(py, &key)?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
178 let start = key.getattr(py, "start")?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
179 let start = UncheckedRevision(start.extract(py)?); |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
180 let start = self.index(py) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
181 .borrow() |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
182 .check_revision(start) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
183 .ok_or_else(|| { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
184 nodemap_error(py, NodeMapError::RevisionNotInIndex(start)) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
185 })?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51215
diff
changeset
|
186 self.index(py).borrow_mut().remove(start).unwrap(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
187 let mut opt = self.get_nodetree(py)?.borrow_mut(); |
49987
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49373
diff
changeset
|
188 let nt = opt.as_mut().unwrap(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
189 nt.invalidate_all(); |
49987
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49373
diff
changeset
|
190 self.fill_nodemap(py, nt)?; |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
191 Ok(()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
192 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
193 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
194 // |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
195 // Reforwarded C index API |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
196 // |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
197 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
198 // index_methods (tp_methods). Same ordering as in revlog.c |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
199 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
200 /// return the gca set of the given revs |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
201 def ancestors(&self, *args, **kw) -> PyResult<PyObject> { |
51246
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
202 let rust_res = self.inner_ancestors(py, args)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
203 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
204 let c_res = self.call_cindex(py, "ancestors", args, kw)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
205 // the algorithm should always provide the results in reverse ordering |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
206 assert_py_eq(py, "ancestors", &rust_res, &c_res)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
207 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
208 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
209 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
210 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
211 /// return the heads of the common ancestors of the given revs |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
212 def commonancestorsheads(&self, *args, **kw) -> PyResult<PyObject> { |
51246
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
213 let rust_res = self.inner_commonancestorsheads(py, args)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
214 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
215 let c_res = self.call_cindex(py, "commonancestorsheads", args, kw)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
216 // the algorithm should always provide the results in reverse ordering |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
217 assert_py_eq(py, "commonancestorsheads", &rust_res, &c_res)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
218 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
219 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
220 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
221 |
44521
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44520
diff
changeset
|
222 /// Clear the index caches and inner py_class data. |
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44520
diff
changeset
|
223 /// It is Python's responsibility to call `update_nodemap_data` again. |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
224 def clearcaches(&self, *args, **kw) -> PyResult<PyObject> { |
44521
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44520
diff
changeset
|
225 self.nt(py).borrow_mut().take(); |
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44520
diff
changeset
|
226 self.docket(py).borrow_mut().take(); |
51207
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51118
diff
changeset
|
227 self.nodemap_mmap(py).borrow_mut().take(); |
51218
4e6620b7fbbb
rust-index: support cache clearing
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
228 self.index(py).borrow_mut().clear_caches(); |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
229 self.call_cindex(py, "clearcaches", args, kw) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
230 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
231 |
47075
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
232 /// 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
|
233 def entry_binary(&self, *args, **kw) -> PyResult<PyObject> { |
51224
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51223
diff
changeset
|
234 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:
51223
diff
changeset
|
235 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:
51223
diff
changeset
|
236 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:
51223
diff
changeset
|
237 |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:
51223
diff
changeset
|
238 .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:
51223
diff
changeset
|
239 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:
51223
diff
changeset
|
240 |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51223
diff
changeset
|
241 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:
51223
diff
changeset
|
242 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:
51223
diff
changeset
|
243 Ok(rust_res) |
47075
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
244 } |
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
245 |
47078
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47075
diff
changeset
|
246 /// return a binary packed version of the header |
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47075
diff
changeset
|
247 def pack_header(&self, *args, **kw) -> PyResult<PyObject> { |
51219
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51218
diff
changeset
|
248 let rindex = self.index(py).borrow(); |
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51218
diff
changeset
|
249 let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); |
51223
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
250 let rust_res = PyBytes::new(py, &packed).into_object(); |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
251 |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
252 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:
51222
diff
changeset
|
253 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:
51222
diff
changeset
|
254 Ok(rust_res) |
47078
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47075
diff
changeset
|
255 } |
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47075
diff
changeset
|
256 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
257 /// compute phases |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
258 def computephasesmapsets(&self, *args, **kw) -> PyResult<PyObject> { |
51241
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
259 let py_roots = args.get_item(py, 0).extract::<PyDict>(py)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
260 let rust_res = self.inner_computephasesmapsets(py, py_roots)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
261 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
262 let c_res = self.call_cindex(py, "computephasesmapsets", args, kw)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
263 assert_py_eq(py, "computephasesmapsets", &rust_res, &c_res)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
264 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
265 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
266 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
267 /// reachableroots |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
268 def reachableroots2(&self, *args, **kw) -> PyResult<PyObject> { |
51243
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
269 let rust_res = self.inner_reachableroots2( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
270 py, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
271 UncheckedRevision(args.get_item(py, 0).extract(py)?), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
272 args.get_item(py, 1), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
273 args.get_item(py, 2), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
274 args.get_item(py, 3).extract(py)?, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
275 )?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
276 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
277 let c_res = self.call_cindex(py, "reachableroots2", args, kw)?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
278 // ordering of C result depends on how the computation went, and |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
279 // Rust result ordering is arbitrary. Hence we compare after |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
280 // sorting the results (in Python to avoid reconverting everything |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
281 // back to Rust structs). |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
282 assert_py_eq_normalized(py, "reachableroots2", &rust_res, &c_res, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
283 |v| format!("sorted({})", v))?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
284 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
285 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
286 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
287 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
288 /// get head revisions |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
289 def headrevs(&self, *args, **kw) -> PyResult<PyObject> { |
51236
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
290 let rust_res = self.inner_headrevs(py)?; |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
291 |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
292 let c_res = self.call_cindex(py, "headrevs", args, kw)?; |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
293 assert_py_eq(py, "headrevs", &rust_res, &c_res)?; |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
294 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
295 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
296 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
297 /// get filtered head revisions |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
298 def headrevsfiltered(&self, *args, **kw) -> PyResult<PyObject> { |
51237
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
299 let rust_res = self.inner_headrevsfiltered(py, &args.get_item(py, 0))?; |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
300 let c_res = self.call_cindex(py, "headrevsfiltered", args, kw)?; |
51238
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
301 |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
302 assert_py_eq(py, "headrevsfiltered", &rust_res, &c_res)?; |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
303 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
304 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
305 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
306 /// True if the object is a snapshot |
51232
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
307 def issnapshot(&self, *args, **kw) -> PyResult<bool> { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
308 let index = self.index(py).borrow(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
309 let result = index |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
310 .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:
51231
diff
changeset
|
311 .map_err(|e| { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
312 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
313 })?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
314 let cresult = self.call_cindex(py, "issnapshot", args, kw)?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
315 assert_eq!(result, cresult.extract(py)?); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51231
diff
changeset
|
316 Ok(result) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
317 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
318 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
319 /// Gather snapshot data in a cache dict |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
320 def findsnapshots(&self, *args, **kw) -> PyResult<PyObject> { |
51233
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
321 let index = self.index(py).borrow(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
322 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:
51232
diff
changeset
|
323 // 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:
51232
diff
changeset
|
324 // 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:
51232
diff
changeset
|
325 // 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:
51232
diff
changeset
|
326 // caches. |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
327 let c_cache = PyDict::new(py); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
328 for (k, v) in cache.items(py) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
329 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:
51232
diff
changeset
|
330 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
331 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
332 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:
51232
diff
changeset
|
333 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:
51232
diff
changeset
|
334 let mut cache_wrapper = PySnapshotsCache{ py, dict: cache }; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
335 index.find_snapshots( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
336 start_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
337 end_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
338 &mut cache_wrapper, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
339 ).map_err(|_| revlog_error(py))?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
340 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
341 let c_args = PyTuple::new( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
342 py, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
343 &[ |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
344 c_cache.clone_ref(py).into_object(), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
345 args.get_item(py, 1), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
346 args.get_item(py, 2) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
347 ] |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
348 ); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
349 self.call_cindex(py, "findsnapshots", &c_args, kw)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
350 assert_py_eq(py, "findsnapshots cache", |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
351 &cache_wrapper.into_object(), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
352 &c_cache.into_object())?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
353 Ok(py.None()) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
354 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
355 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
356 /// determine revisions with deltas to reconstruct fulltext |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
357 def deltachain(&self, *args, **kw) -> PyResult<PyObject> { |
51234
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
358 let index = self.index(py).borrow(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
359 let rev = args.get_item(py, 0).extract::<BaseRevision>(py)?.into(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
360 let stop_rev = |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
361 args.get_item(py, 1).extract::<Option<BaseRevision>>(py)?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
362 let rev = index.check_revision(rev).ok_or_else(|| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
363 nodemap_error(py, NodeMapError::RevisionNotInIndex(rev)) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
364 })?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
365 let stop_rev = if let Some(stop_rev) = stop_rev { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
366 let stop_rev = UncheckedRevision(stop_rev); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
367 Some(index.check_revision(stop_rev).ok_or_else(|| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
368 nodemap_error(py, NodeMapError::RevisionNotInIndex(stop_rev)) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
369 })?) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
370 } else {None}; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
371 let (chain, stopped) = index.delta_chain(rev, stop_rev).map_err(|e| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
372 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
373 })?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
374 |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
375 let cresult = self.call_cindex(py, "deltachain", args, kw)?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
376 let cchain: Vec<BaseRevision> = |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
377 cresult.get_item(py, 0)?.extract::<Vec<BaseRevision>>(py)?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
378 let chain: Vec<_> = chain.into_iter().map(|r| r.0).collect(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
379 assert_eq!(chain, cchain); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
380 assert_eq!(stopped, cresult.get_item(py, 1)?.extract(py)?); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
381 |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
382 Ok( |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
383 PyTuple::new( |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
384 py, |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
385 &[ |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
386 chain.into_py_object(py).into_object(), |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
387 stopped.into_py_object(py).into_object() |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
388 ] |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
389 ).into_object() |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
390 ) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51233
diff
changeset
|
391 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
392 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
393 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
394 /// slice planned chunk read to reach a density threshold |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
395 def slicechunktodensity(&self, *args, **kw) -> PyResult<PyObject> { |
51239
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
396 let rust_res = self.inner_slicechunktodensity( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
397 py, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
398 args.get_item(py, 0), |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
399 args.get_item(py, 1).extract(py)?, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
400 args.get_item(py, 2).extract(py)? |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
401 )?; |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
402 |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
403 let c_res = self.call_cindex(py, "slicechunktodensity", args, kw)?; |
51240
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
404 assert_py_eq(py, "slicechunktodensity", &rust_res, &c_res)?; |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
405 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
406 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
407 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
408 // index_sequence_methods and index_mapping_methods. |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
409 // |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
410 // Since we call back through the high level Python API, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
411 // there's no point making a distinction between index_get |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
412 // and index_getitem. |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
413 // gracinet 2023: this above is no longer true for the pure Rust impl |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
414 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
415 def __len__(&self) -> PyResult<usize> { |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
416 self.len(py) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
417 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
418 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
419 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
420 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:
51225
diff
changeset
|
421 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
422 // this conversion seems needless, but that's actually because |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
423 // `index_getitem` does not handle conversion from PyLong, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
424 // which expressions such as [e for e in index] internally use. |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
425 // Note that we don't seem to have a direct way to call |
44521
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44520
diff
changeset
|
426 // PySequence_GetItem (does the job), which would possibly be better |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
427 // for performance |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
428 // 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:
51225
diff
changeset
|
429 // 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:
51225
diff
changeset
|
430 // node id. |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
431 let c_key = match key.extract::<BaseRevision>(py) { |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
432 Ok(rev) => rev.to_py_object(py).into_object(), |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
433 Err(_) => key, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
434 }; |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
435 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:
51225
diff
changeset
|
436 |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
437 assert_py_eq(py, "__getitem__", &rust_res, &c_res)?; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
438 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
439 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
440 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
441 def __contains__(&self, item: PyObject) -> PyResult<bool> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
442 // ObjectProtocol does not seem to provide contains(), so |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
443 // this is an equivalent implementation of the index_contains() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
444 // defined in revlog.c |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
445 let cindex = self.cindex(py).borrow(); |
50988
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49987
diff
changeset
|
446 match item.extract::<i32>(py) { |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
447 Ok(rev) => { |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
448 Ok(rev >= -1 && rev < self.len(py)? as BaseRevision) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
449 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
450 Err(_) => { |
51228
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
451 let item_bytes: PyBytes = item.extract(py)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
452 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:
51227
diff
changeset
|
453 |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
454 let c_res = cindex.inner().call_method( |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
455 py, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
456 "has_node", |
51228
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
457 PyTuple::new(py, &[item.clone_ref(py)]), |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
458 None)? |
51228
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
459 .extract(py)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
460 |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
461 assert_eq!(rust_res, c_res); |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51227
diff
changeset
|
462 Ok(rust_res) |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
463 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
464 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
465 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
466 |
44518
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
467 def nodemap_data_all(&self) -> PyResult<PyBytes> { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
468 self.inner_nodemap_data_all(py) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
469 } |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
470 |
44519
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
471 def nodemap_data_incremental(&self) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
472 self.inner_nodemap_data_incremental(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
473 } |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
474 def update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
475 &self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
476 docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
477 nm_data: PyObject |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
478 ) -> PyResult<PyObject> { |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
479 self.inner_update_nodemap_data(py, docket, nm_data) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
480 } |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
481 |
46974
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46500
diff
changeset
|
482 @property |
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46500
diff
changeset
|
483 def entry_size(&self) -> PyResult<PyInt> { |
51250
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
484 let rust_res: PyInt = INDEX_ENTRY_SIZE.to_py_object(py); |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
485 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
486 let c_res = self.cindex(py).borrow().inner() |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
487 .getattr(py, "entry_size")?; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
488 assert_py_eq(py, "entry_size", rust_res.as_object(), &c_res)?; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
489 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
490 Ok(rust_res) |
46974
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46500
diff
changeset
|
491 } |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
492 |
47279
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47078
diff
changeset
|
493 @property |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47078
diff
changeset
|
494 def rust_ext_compat(&self) -> PyResult<PyInt> { |
51250
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
495 // will be entirely removed when the Rust index yet useful to |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
496 // implement in Rust to detangle things when removing `self.cindex` |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
497 let rust_res: PyInt = 1.to_py_object(py); |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
498 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
499 let c_res = self.cindex(py).borrow().inner() |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
500 .getattr(py, "rust_ext_compat")?; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
501 assert_py_eq(py, "rust_ext_compat", rust_res.as_object(), &c_res)?; |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
502 |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
503 Ok(rust_res) |
47279
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47078
diff
changeset
|
504 } |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47078
diff
changeset
|
505 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
506 }); |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
507 |
51208
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
508 /// Take a (potentially) mmap'ed buffer, and return the underlying Python |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
509 /// buffer along with the Rust slice into said buffer. We need to keep the |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
510 /// Python buffer around, otherwise we'd get a dangling pointer once the buffer |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
511 /// is freed from Python's side. |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
512 /// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
513 /// # Safety |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
514 /// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
515 /// The caller must make sure that the buffer is kept around for at least as |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
516 /// long as the slice. |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
517 #[deny(unsafe_op_in_unsafe_fn)] |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
518 unsafe fn mmap_keeparound( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
519 py: Python, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
520 data: PyObject, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
521 ) -> PyResult<( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
522 PyBuffer, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
523 Box<dyn std::ops::Deref<Target = [u8]> + Send + 'static>, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
524 )> { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
525 let buf = PyBuffer::get(py, &data)?; |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
526 let len = buf.item_count(); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
527 |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
528 // Build a slice from the mmap'ed buffer data |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
529 let cbuf = buf.buf_ptr(); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
530 let bytes = if std::mem::size_of::<u8>() == buf.item_size() |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
531 && buf.is_c_contiguous() |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
532 && u8::is_compatible_format(buf.format()) |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
533 { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
534 unsafe { std::slice::from_raw_parts(cbuf as *const u8, len) } |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
535 } else { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
536 return Err(PyErr::new::<ValueError, _>( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
537 py, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
538 "Nodemap data buffer has an invalid memory representation" |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
539 .to_string(), |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
540 )); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
541 }; |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
542 |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
543 Ok((buf, Box::new(bytes))) |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
544 } |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
545 |
51213
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
546 fn py_tuple_to_revision_data_params( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
547 py: Python, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
548 tuple: PyTuple, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
549 ) -> PyResult<RevisionDataParams> { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
550 if tuple.len(py) < 8 { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
551 // this is better than the panic promised by tup.get_item() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
552 return Err(PyErr::new::<IndexError, _>( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
553 py, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
554 "tuple index out of range", |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
555 )); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
556 } |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
557 let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
558 let node_id = tuple |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
559 .get_item(py, 7) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
560 .extract::<PyBytes>(py)? |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
561 .data(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
562 .try_into() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
563 .unwrap(); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
564 let flags = (offset_or_flags & 0xFFFF) as u16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
565 let data_offset = offset_or_flags >> 16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
566 Ok(RevisionDataParams { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
567 flags, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
568 data_offset, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
569 data_compressed_length: tuple.get_item(py, 1).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
570 data_uncompressed_length: tuple.get_item(py, 2).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
571 data_delta_base: tuple.get_item(py, 3).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
572 link_rev: tuple.get_item(py, 4).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
573 parent_rev_1: tuple.get_item(py, 5).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
574 parent_rev_2: tuple.get_item(py, 6).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
575 node_id, |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
576 ..Default::default() |
51213
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
577 }) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
578 } |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
579 fn revision_data_params_to_py_tuple( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
580 py: Python, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
581 params: RevisionDataParams, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
582 ) -> PyTuple { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
583 PyTuple::new( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
584 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
585 &[ |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
586 params.data_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
587 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
588 .data_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
589 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
590 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
591 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
592 .data_uncompressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
593 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
594 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
595 params.data_delta_base.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
596 params.link_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
597 params.parent_rev_1.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
598 params.parent_rev_2.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
599 PyBytes::new(py, ¶ms.node_id) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
600 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
601 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
602 params._sidedata_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
603 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
604 ._sidedata_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
605 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
606 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
607 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
608 .data_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
609 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
610 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
611 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
612 ._sidedata_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
613 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
614 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
615 params._rank.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
616 ], |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
617 ) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
618 } |
51213
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
619 |
51233
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
620 struct PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
621 py: Python<'p>, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
622 dict: PyDict, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
623 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
624 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
625 impl<'p> PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
626 fn into_object(self) -> PyObject { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
627 self.dict.into_object() |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
628 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
629 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
630 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
631 impl<'p> SnapshotsCache for PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
632 fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
633 &mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
634 rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
635 value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
636 ) -> Result<(), RevlogError> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
637 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:
51232
diff
changeset
|
638 match self.dict.get_item(self.py, rev) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
639 Some(obj) => obj |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
640 .extract::<PySet>(self.py) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
641 .and_then(|set| set.add(self.py, pyvalue)), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
642 None => PySet::new(self.py, vec![pyvalue]) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
643 .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:
51232
diff
changeset
|
644 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
645 .map_err(|_| { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
646 RevlogError::Other(HgError::unsupported( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
647 "Error in Python caches handling", |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
648 )) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
649 }) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
650 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
651 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51232
diff
changeset
|
652 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
653 impl MixedIndex { |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
654 fn new( |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
655 py: Python, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
656 cindex: PyObject, |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
657 data: PyObject, |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
658 header: u32, |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
659 ) -> PyResult<MixedIndex> { |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
660 // Safety: we keep the buffer around inside the class as `index_mmap` |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
661 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
662 |
44513
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
663 Self::create_instance( |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
664 py, |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
665 RefCell::new(cindex::Index::new(py, cindex)?), |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
666 RefCell::new( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
667 hg::index::Index::new( |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
668 bytes, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
669 IndexHeader::parse(&header.to_be_bytes()) |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
670 .expect("default header is broken") |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
671 .unwrap(), |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
672 ) |
51252
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
673 .map_err(|e| { |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
674 revlog_error_with_msg(py, e.to_string().as_bytes()) |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
675 })?, |
51212
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
676 ), |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
677 RefCell::new(None), |
44519
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
678 RefCell::new(None), |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
679 RefCell::new(None), |
51211
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
680 RefCell::new(Some(buf)), |
44513
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
681 ) |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
682 } |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
683 |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
684 fn len(&self, py: Python) -> PyResult<usize> { |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
685 let rust_index_len = self.index(py).borrow().len(); |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
686 let cindex_len = self.cindex(py).borrow().inner().len(py)?; |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
687 assert_eq!(rust_index_len, cindex_len); |
51250
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51246
diff
changeset
|
688 Ok(rust_index_len) |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
689 } |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
690 |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
691 /// This is scaffolding at this point, but it could also become |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
692 /// a way to start a persistent nodemap or perform a |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
693 /// vacuum / repack operation |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
694 fn fill_nodemap( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
695 &self, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
696 py: Python, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
697 nt: &mut NodeTree, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
698 ) -> PyResult<PyObject> { |
51227
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
699 let index = self.index(py).borrow(); |
51214
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51213
diff
changeset
|
700 for r in 0..self.len(py)? { |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
701 let rev = Revision(r as BaseRevision); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
702 // in this case node() won't ever return None |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
703 nt.insert(&*index, index.node(rev).unwrap(), rev) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
704 .map_err(|e| nodemap_error(py, e))? |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
705 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
706 Ok(py.None()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
707 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
708 |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
709 fn get_nodetree<'a>( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
710 &'a self, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
711 py: Python<'a>, |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
712 ) -> PyResult<&'a RefCell<Option<NodeTree>>> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
713 if self.nt(py).borrow().is_none() { |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50990
diff
changeset
|
714 let readonly = Box::<Vec<_>>::default(); |
44517
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
715 let mut nt = NodeTree::load_bytes(readonly, 0); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
716 self.fill_nodemap(py, &mut nt)?; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
717 self.nt(py).borrow_mut().replace(nt); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
718 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
719 Ok(self.nt(py)) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
720 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44516
diff
changeset
|
721 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
722 /// forward a method call to the underlying C index |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
723 fn call_cindex( |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
724 &self, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
725 py: Python, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
726 name: &str, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
727 args: &PyTuple, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
728 kwargs: Option<&PyDict>, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
729 ) -> PyResult<PyObject> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
730 self.cindex(py) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
731 .borrow() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
732 .inner() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
733 .call_method(py, name, args, kwargs) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
734 } |
44013
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43966
diff
changeset
|
735 |
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43966
diff
changeset
|
736 pub fn clone_cindex(&self, py: Python) -> cindex::Index { |
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43966
diff
changeset
|
737 self.cindex(py).borrow().clone_ref(py) |
2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43966
diff
changeset
|
738 } |
44518
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
739 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
740 /// Returns the full nodemap bytes to be written as-is to disk |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
741 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
742 let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap(); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
743 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes(); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
744 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
745 // If there's anything readonly, we need to build the data again from |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
746 // scratch |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
747 let bytes = if readonly.len() > 0 { |
51118
532e74ad3ff6
rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50990
diff
changeset
|
748 let mut nt = NodeTree::load_bytes(Box::<Vec<_>>::default(), 0); |
44518
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
749 self.fill_nodemap(py, &mut nt)?; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
750 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
751 let (readonly, bytes) = nt.into_readonly_and_added_bytes(); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
752 assert_eq!(readonly.len(), 0); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
753 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
754 bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
755 } else { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
756 bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
757 }; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
758 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
759 let bytes = PyBytes::new(py, &bytes); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
760 Ok(bytes) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44517
diff
changeset
|
761 } |
44519
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
762 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
763 /// Returns the last saved docket along with the size of any changed data |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
764 /// (in number of blocks), and said data as bytes. |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
765 fn inner_nodemap_data_incremental( |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
766 &self, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
767 py: Python, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
768 ) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
769 let docket = self.docket(py).borrow(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
770 let docket = match docket.as_ref() { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
771 Some(d) => d, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
772 None => return Ok(py.None()), |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
773 }; |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
774 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
775 let node_tree = self.get_nodetree(py)?.borrow_mut().take().unwrap(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
776 let masked_blocks = node_tree.masked_readonly_blocks(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
777 let (_, data) = node_tree.into_readonly_and_added_bytes(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
778 let changed = masked_blocks * std::mem::size_of::<Block>(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
779 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
780 Ok((docket, changed, PyBytes::new(py, &data)) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
781 .to_py_object(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
782 .into_object()) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44518
diff
changeset
|
783 } |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
784 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
785 /// Update the nodemap from the new (mmaped) data. |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
786 /// The docket is kept as a reference for later incremental calls. |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
787 fn inner_update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
788 &self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
789 py: Python, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
790 docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
791 nm_data: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
792 ) -> PyResult<PyObject> { |
51208
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
793 // Safety: we keep the buffer around inside the class as `nodemap_mmap` |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
794 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? }; |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
795 let len = buf.item_count(); |
51207
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51118
diff
changeset
|
796 self.nodemap_mmap(py).borrow_mut().replace(buf); |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
797 |
51208
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
798 let mut nt = NodeTree::load_bytes(bytes, len); |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
799 |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
800 let data_tip = docket |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
801 .getattr(py, "tip_rev")? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
802 .extract::<BaseRevision>(py)? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
803 .into(); |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
804 self.docket(py).borrow_mut().replace(docket.clone_ref(py)); |
51227
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51226
diff
changeset
|
805 let idx = self.index(py).borrow(); |
50988
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49987
diff
changeset
|
806 let data_tip = idx.check_revision(data_tip).ok_or_else(|| { |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49987
diff
changeset
|
807 nodemap_error(py, NodeMapError::RevisionNotInIndex(data_tip)) |
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49987
diff
changeset
|
808 })?; |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
809 let current_tip = idx.len(); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
810 |
50990
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
811 for r in (data_tip.0 + 1)..current_tip as BaseRevision { |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50988
diff
changeset
|
812 let rev = Revision(r); |
44520
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
813 // in this case node() won't ever return None |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
814 nt.insert(&*idx, idx.node(rev).unwrap(), rev) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
815 .map_err(|e| nodemap_error(py, e))? |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
816 } |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
817 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
818 *self.nt(py).borrow_mut() = Some(nt); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
819 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
820 Ok(py.None()) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44519
diff
changeset
|
821 } |
51226
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
822 |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
823 fn inner_getitem(&self, py: Python, key: PyObject) -> PyResult<PyObject> { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
824 let idx = self.index(py).borrow(); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
825 Ok(match key.extract::<BaseRevision>(py) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
826 Ok(key_as_int) => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
827 let entry_params = if key_as_int == NULL_REVISION.0 { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
828 RevisionDataParams::default() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
829 } else { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
830 let rev = UncheckedRevision(key_as_int); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
831 match idx.entry_as_params(rev) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
832 Some(e) => e, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
833 None => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
834 return Err(PyErr::new::<IndexError, _>( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
835 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
836 "revlog index out of range", |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
837 )); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
838 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
839 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
840 }; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
841 revision_data_params_to_py_tuple(py, entry_params) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
842 .into_object() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
843 } |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
844 _ => 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:
51225
diff
changeset
|
845 || py.None(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
846 |py_rev| py_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
847 ), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
848 }) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51225
diff
changeset
|
849 } |
51236
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
850 |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
851 fn inner_headrevs(&self, py: Python) -> PyResult<PyObject> { |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
852 let index = &mut *self.index(py).borrow_mut(); |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
853 let as_vec: Vec<PyObject> = index |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
854 .head_revs() |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
855 .map_err(|e| graph_error(py, e))? |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
856 .iter() |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
857 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
858 .collect(); |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
859 Ok(PyList::new(py, &as_vec).into_object()) |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
860 } |
51237
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
861 |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
862 fn inner_headrevsfiltered( |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
863 &self, |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
864 py: Python, |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
865 filtered_revs: &PyObject, |
51238
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
866 ) -> PyResult<PyObject> { |
51237
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
867 let index = &mut *self.index(py).borrow_mut(); |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
868 let filtered_revs = rev_pyiter_collect(py, filtered_revs, index)?; |
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
869 |
51238
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
870 let as_vec: Vec<PyObject> = index |
51237
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
871 .head_revs_filtered(&filtered_revs) |
51238
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
872 .map_err(|e| graph_error(py, e))? |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
873 .iter() |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
874 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
875 .collect(); |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51237
diff
changeset
|
876 Ok(PyList::new(py, &as_vec).into_object()) |
51237
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51236
diff
changeset
|
877 } |
51239
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
878 |
51246
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
879 fn inner_ancestors( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
880 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
881 py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
882 py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
883 ) -> PyResult<PyObject> { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
884 let index = &mut *self.index(py).borrow_mut(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
885 let revs: Vec<_> = rev_pyiter_collect(py, py_revs.as_object(), index)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
886 let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
887 .ancestors(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
888 .map_err(|e| graph_error(py, e))? |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
889 .iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
890 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
891 .collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
892 Ok(PyList::new(py, &as_vec).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
893 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
894 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
895 fn inner_commonancestorsheads( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
896 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
897 py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
898 py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
899 ) -> PyResult<PyObject> { |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
900 let index = &mut *self.index(py).borrow_mut(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
901 let revs: Vec<_> = rev_pyiter_collect(py, py_revs.as_object(), index)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
902 let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
903 .common_ancestor_heads(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
904 .map_err(|e| graph_error(py, e))? |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
905 .iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
906 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
907 .collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
908 Ok(PyList::new(py, &as_vec).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
909 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
910 |
51241
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
911 fn inner_computephasesmapsets( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
912 &self, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
913 py: Python, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
914 py_roots: PyDict, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
915 ) -> PyResult<PyObject> { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
916 let index = &*self.index(py).borrow(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
917 let opt = self.get_nodetree(py)?.borrow(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
918 let nt = opt.as_ref().unwrap(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
919 let roots: Result<HashMap<Phase, Vec<Revision>>, PyErr> = py_roots |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
920 .items_list(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
921 .iter(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
922 .map(|r| { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
923 let phase = r.get_item(py, 0)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
924 let nodes = r.get_item(py, 1)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
925 // Transform the nodes from Python to revs here since we |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
926 // have access to the nodemap |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
927 let revs: Result<_, _> = nodes |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
928 .iter(py)? |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
929 .map(|node| match node?.extract::<PyBytes>(py) { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
930 Ok(py_bytes) => { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
931 let node = node_from_py_bytes(py, &py_bytes)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
932 nt.find_bin(index, node.into()) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
933 .map_err(|e| nodemap_error(py, e))? |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
934 .ok_or_else(|| revlog_error(py)) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
935 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
936 Err(e) => Err(e), |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
937 }) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
938 .collect(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
939 let phase = Phase::try_from(phase.extract::<usize>(py)?) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
940 .map_err(|_| revlog_error(py)); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
941 Ok((phase?, revs?)) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
942 }) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
943 .collect(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
944 let (len, phase_maps) = index |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
945 .compute_phases_map_sets(roots?) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
946 .map_err(|e| graph_error(py, e))?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
947 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
948 // Ugly hack, but temporary |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
949 const IDX_TO_PHASE_NUM: [usize; 4] = [1, 2, 32, 96]; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
950 let py_phase_maps = PyDict::new(py); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
951 for (idx, roots) in phase_maps.iter().enumerate() { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
952 let phase_num = IDX_TO_PHASE_NUM[idx].into_py_object(py); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
953 // OPTIM too bad we have to collect here. At least, we could |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
954 // reuse the same Vec and allocate it with capacity at |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
955 // max(len(phase_maps) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
956 let roots_vec: Vec<PyInt> = roots |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
957 .iter() |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
958 .map(|r| PyRevision::from(*r).into_py_object(py)) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
959 .collect(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
960 py_phase_maps.set_item( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
961 py, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
962 phase_num, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
963 PySet::new(py, roots_vec)?, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
964 )?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
965 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
966 Ok(PyTuple::new( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
967 py, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
968 &[ |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
969 len.into_py_object(py).into_object(), |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
970 py_phase_maps.into_object(), |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
971 ], |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
972 ) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
973 .into_object()) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
974 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51240
diff
changeset
|
975 |
51239
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
976 fn inner_slicechunktodensity( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
977 &self, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
978 py: Python, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
979 revs: PyObject, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
980 target_density: f64, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
981 min_gap_size: usize, |
51240
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
982 ) -> PyResult<PyObject> { |
51239
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
983 let index = &mut *self.index(py).borrow_mut(); |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
984 let revs: Vec<_> = rev_pyiter_collect(py, &revs, index)?; |
51240
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
985 let as_nested_vec = |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
986 index.slice_chunk_to_density(&revs, target_density, min_gap_size); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
987 let mut res = Vec::with_capacity(as_nested_vec.len()); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
988 let mut py_chunk = Vec::new(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
989 for chunk in as_nested_vec { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
990 py_chunk.clear(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
991 py_chunk.reserve_exact(chunk.len()); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
992 for rev in chunk { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
993 py_chunk.push( |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
994 PyRevision::from(rev).into_py_object(py).into_object(), |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
995 ); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
996 } |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
997 res.push(PyList::new(py, &py_chunk).into_object()); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
998 } |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
999 // This is just to do the same as C, not sure why it does this |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
1000 if res.len() == 1 { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
1001 Ok(PyTuple::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
1002 } else { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
1003 Ok(PyList::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51239
diff
changeset
|
1004 } |
51239
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51238
diff
changeset
|
1005 } |
51243
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1006 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1007 fn inner_reachableroots2( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1008 &self, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1009 py: Python, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1010 min_root: UncheckedRevision, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1011 heads: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1012 roots: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1013 include_path: bool, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1014 ) -> PyResult<PyObject> { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1015 let index = &*self.index(py).borrow(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1016 let heads = rev_pyiter_collect_or_else(py, &heads, index, |_rev| { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1017 PyErr::new::<IndexError, _>(py, "head out of range") |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1018 })?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1019 let roots: Result<_, _> = roots |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1020 .iter(py)? |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1021 .map(|r| { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1022 r.and_then(|o| match o.extract::<PyRevision>(py) { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1023 Ok(r) => Ok(UncheckedRevision(r.0)), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1024 Err(e) => Err(e), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1025 }) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1026 }) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1027 .collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1028 let as_set = index |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1029 .reachable_roots(min_root, heads, roots?, include_path) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1030 .map_err(|e| graph_error(py, e))?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1031 let as_vec: Vec<PyObject> = as_set |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1032 .iter() |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1033 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1034 .collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1035 Ok(PyList::new(py, &as_vec).into_object()) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51241
diff
changeset
|
1036 } |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1037 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1038 |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1039 fn revlog_error(py: Python) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1040 match py |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1041 .import("mercurial.error") |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1042 .and_then(|m| m.get(py, "RevlogError")) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1043 { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1044 Err(e) => e, |
47316
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47279
diff
changeset
|
1045 Ok(cls) => PyErr::from_instance( |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47279
diff
changeset
|
1046 py, |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47279
diff
changeset
|
1047 cls.call(py, (py.None(),), None).ok().into_py_object(py), |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47279
diff
changeset
|
1048 ), |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1049 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1050 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1051 |
51252
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1052 fn revlog_error_with_msg(py: Python, msg: &[u8]) -> PyErr { |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1053 match py |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1054 .import("mercurial.error") |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1055 .and_then(|m| m.get(py, "RevlogError")) |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1056 { |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1057 Err(e) => e, |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1058 Ok(cls) => PyErr::from_instance( |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1059 py, |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1060 cls.call(py, (PyBytes::new(py, msg),), None) |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1061 .ok() |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1062 .into_py_object(py), |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1063 ), |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1064 } |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1065 } |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51250
diff
changeset
|
1066 |
51236
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1067 fn graph_error(py: Python, _err: hg::GraphError) -> PyErr { |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1068 // ParentOutOfRange is currently the only alternative |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1069 // in `hg::GraphError`. The C index always raises this simple ValueError. |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1070 PyErr::new::<ValueError, _>(py, "parent out of range") |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1071 } |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51235
diff
changeset
|
1072 |
51220
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1073 fn nodemap_rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr { |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1074 PyErr::new::<ValueError, _>( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1075 py, |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1076 format!( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1077 "Inconsistency: Revision {} found in nodemap \ |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1078 is not in revlog index", |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1079 rev |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1080 ), |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1081 ) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1082 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1083 |
51221
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51220
diff
changeset
|
1084 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:
51220
diff
changeset
|
1085 PyErr::new::<ValueError, _>( |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51220
diff
changeset
|
1086 py, |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51220
diff
changeset
|
1087 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:
51220
diff
changeset
|
1088 ) |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51220
diff
changeset
|
1089 } |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51220
diff
changeset
|
1090 |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1091 /// Standard treatment of NodeMapError |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1092 fn nodemap_error(py: Python, err: NodeMapError) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1093 match err { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1094 NodeMapError::MultipleResults => revlog_error(py), |
51220
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1095 NodeMapError::RevisionNotInIndex(r) => nodemap_rev_not_in_index(py, r), |
44516
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1096 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1097 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44513
diff
changeset
|
1098 |
51235
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1099 /// assert two Python objects to be equal from a Python point of view |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1100 /// |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1101 /// `method` is a label for the assertion error message, intended to be the |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1102 /// name of the caller. |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1103 /// `normalizer` is a function that takes a Python variable name and returns |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1104 /// an expression that the conparison will actually use. |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1105 /// Foe example: `|v| format!("sorted({})", v)` |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1106 fn assert_py_eq_normalized( |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1107 py: Python, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1108 method: &str, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1109 rust: &PyObject, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1110 c: &PyObject, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1111 normalizer: impl FnOnce(&str) -> String + Copy, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1112 ) -> PyResult<()> { |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1113 let locals = PyDict::new(py); |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1114 locals.set_item(py, "rust".into_py_object(py).into_object(), rust)?; |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1115 locals.set_item(py, "c".into_py_object(py).into_object(), c)?; |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1116 // let lhs = format!(normalizer_fmt, "rust"); |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1117 // let rhs = format!(normalizer_fmt, "c"); |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1118 let is_eq: PyBool = py |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1119 .eval( |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1120 &format!("{} == {}", &normalizer("rust"), &normalizer("c")), |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1121 None, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1122 Some(&locals), |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1123 )? |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1124 .extract(py)?; |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1125 assert!( |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1126 is_eq.is_true(), |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1127 "{} results differ. Rust: {:?} C: {:?} (before any normalization)", |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1128 method, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1129 rust, |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1130 c |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1131 ); |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1132 Ok(()) |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1133 } |
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1134 |
51222
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1135 fn assert_py_eq( |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1136 py: Python, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1137 method: &str, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1138 rust: &PyObject, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1139 c: &PyObject, |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1140 ) -> PyResult<()> { |
51235
050098d60c30
rust-index: variant of assert_py_eq with normalizer expression
Georges Racinet <georges.racinet@octobus.net>
parents:
51234
diff
changeset
|
1141 assert_py_eq_normalized(py, method, rust, c, |v| v.to_owned()) |
51222
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1142 } |
52bbb57a76ad
rust-index: results comparison helper with details
Georges Racinet <georges.racinet@octobus.net>
parents:
51221
diff
changeset
|
1143 |
43966
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1144 /// Create the module, with __package__ given from parent |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1145 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1146 let dotted_name = &format!("{}.revlog", package); |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1147 let m = PyModule::new(py, dotted_name)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1148 m.add(py, "__package__", package)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1149 m.add(py, "__doc__", "RevLog - Rust implementations")?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1150 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1151 m.add_class::<MixedIndex>(py)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1152 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1153 let sys = PyModule::import(py, "sys")?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1154 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1155 sys_modules.set_item(py, dotted_name, &m)?; |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1156 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1157 Ok(m) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43951
diff
changeset
|
1158 } |