annotate rust/hg-cpython/src/revlog.rs @ 52771:2fb13c3f4496

rust: add GraphError::ParentOutOfOrder This will be used in a follow-up commit that creates a data structure optimized for inserting revisions in descending order, since it will need to fail if a revision number is greater than its descendant (meaning the graph is corrupted).
author Mitchell Kember <mkember@janestreet.com>
date Fri, 07 Feb 2025 16:07:35 -0500
parents c2480ac4c5e2
children 8de68446a5bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43945
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 // revlog.rs
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 //
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
3 // Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
43945
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 //
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 // This software may be used and distributed according to the terms of the
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 // GNU General Public License version 2 or any later version.
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
7 #![allow(non_snake_case)]
43945
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
9 use crate::{
51219
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
10 conversion::{rev_pyiter_collect, rev_pyiter_collect_or_else},
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
11 pybytes_deref::{PyBufferDeref, PyBytesDeref},
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
12 utils::{node_from_py_bytes, node_from_py_object},
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
13 PyRevision,
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
14 };
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
15 use cpython::{
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
16 buffer::{Element, PyBuffer},
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
17 exc::{IndexError, ValueError},
51245
8b243e2a3bc4 rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents: 51244
diff changeset
18 ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, PyList,
52411
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
19 PyModule, PyObject, PyResult, PySet, PySharedRef, PyTuple, PyType, Python,
51245
8b243e2a3bc4 rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents: 51244
diff changeset
20 PythonObject, ToPyObject, UnsafePyLeaked,
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
21 };
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
22 use hg::{
51209
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
23 errors::HgError,
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
24 fncache::FnCache,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
25 revlog::{
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
26 compression::CompressionConfig,
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
27 index::{
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
28 Index, IndexHeader, Phase, RevisionDataParams, SnapshotsCache,
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
29 INDEX_ENTRY_SIZE,
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
30 },
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
31 inner_revlog::{InnerRevlog as CoreInnerRevlog, RevisionBuffer},
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
32 nodemap::{Block, NodeMap, NodeMapError, NodeTree as CoreNodeTree},
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
33 options::{
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
34 RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
35 RevlogOpenOptions,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
36 },
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
37 Graph, NodePrefix, RevlogError, RevlogIndex, RevlogType,
51226
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51222
diff changeset
38 },
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
39 transaction::Transaction,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
40 utils::files::{get_bytes_from_path, get_path_from_bytes},
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
41 vfs::FnCacheVfs,
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
42 BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION,
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
43 };
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
44 use std::{
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
45 cell::{Cell, RefCell},
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
46 collections::{HashMap, HashSet},
52176
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
47 sync::atomic::{AtomicBool, AtomicUsize, Ordering},
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
48 sync::OnceLock,
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
49 };
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
50 use vcsgraph::graph::Graph as VCSGraph;
43945
f98f0e3ddaa1 rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
51
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
52 pub struct PySharedIndex {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
53 /// The underlying hg-core index
52411
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
54 pub inner: &'static Index,
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
55 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
56
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
57 /// Return a Struct implementing the Graph trait
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
58 pub(crate) fn py_rust_index_to_graph(
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
59 py: Python,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
60 index_proxy: PyObject,
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
61 ) -> PyResult<UnsafePyLeaked<PySharedIndex>> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
62 let inner_revlog = index_proxy.getattr(py, "inner")?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
63 let inner_revlog = inner_revlog.extract::<InnerRevlog>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
64 let leaked = inner_revlog.inner(py).leak_immutable();
51252
24d3298189d7 rust-index: document safety invariants being upheld for every `unsafe` block
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51251
diff changeset
65 // Safety: we don't leak the "faked" reference out of the `UnsafePyLeaked`
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
66 Ok(unsafe { leaked.map(py, |idx| PySharedIndex { inner: &idx.index }) })
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
67 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
68
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
69 impl Clone for PySharedIndex {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
70 fn clone(&self) -> Self {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
71 Self { inner: self.inner }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
72 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
73 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
74
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
75 impl Graph for PySharedIndex {
51255
8b89f7cc953a rust-index: allow inlining VCSGraph parents across crates
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51252
diff changeset
76 #[inline(always)]
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
77 fn parents(&self, rev: Revision) -> Result<[Revision; 2], hg::GraphError> {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
78 self.inner.parents(rev)
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
79 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
80 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
81
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
82 impl VCSGraph for PySharedIndex {
51255
8b89f7cc953a rust-index: allow inlining VCSGraph parents across crates
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51252
diff changeset
83 #[inline(always)]
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
84 fn parents(
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
85 &self,
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
86 rev: BaseRevision,
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
87 ) -> Result<vcsgraph::graph::Parents, vcsgraph::graph::GraphReadError>
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
88 {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
89 // FIXME This trait should be reworked to decide between Revision
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
90 // and UncheckedRevision, get better errors names, etc.
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
91 match Graph::parents(self, Revision(rev)) {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
92 Ok(parents) => {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
93 Ok(vcsgraph::graph::Parents([parents[0].0, parents[1].0]))
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
94 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
95 Err(hg::GraphError::ParentOutOfRange(rev)) => {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
96 Err(vcsgraph::graph::GraphReadError::KeyedInvalidKey(rev.0))
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
97 }
52771
2fb13c3f4496 rust: add GraphError::ParentOutOfOrder
Mitchell Kember <mkember@janestreet.com>
parents: 52411
diff changeset
98 Err(hg::GraphError::ParentOutOfOrder(_)) => {
2fb13c3f4496 rust: add GraphError::ParentOutOfOrder
Mitchell Kember <mkember@janestreet.com>
parents: 52411
diff changeset
99 Err(vcsgraph::graph::GraphReadError::InconsistentGraphData)
2fb13c3f4496 rust: add GraphError::ParentOutOfOrder
Mitchell Kember <mkember@janestreet.com>
parents: 52411
diff changeset
100 }
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
101 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
102 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
103 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
104
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
105 impl RevlogIndex for PySharedIndex {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
106 fn len(&self) -> usize {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
107 self.inner.len()
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
108 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
109 fn node(&self, rev: Revision) -> Option<&Node> {
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
110 self.inner.node(rev)
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
111 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
112 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
113
51184
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
114 /// Take a (potentially) mmap'ed buffer, and return the underlying Python
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
115 /// buffer along with the Rust slice into said buffer. We need to keep the
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
116 /// Python buffer around, otherwise we'd get a dangling pointer once the buffer
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
117 /// is freed from Python's side.
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
118 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
119 /// # Safety
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
120 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
121 /// The caller must make sure that the buffer is kept around for at least as
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
122 /// long as the slice.
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
123 #[deny(unsafe_op_in_unsafe_fn)]
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
124 unsafe fn mmap_keeparound(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
125 py: Python,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
126 data: PyObject,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
127 ) -> PyResult<(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
128 PyBuffer,
51230
ca81cd96000a rust-index: add Sync bound to all relevant mmap-derived values
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51229
diff changeset
129 Box<dyn std::ops::Deref<Target = [u8]> + Send + Sync + 'static>,
51184
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
130 )> {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
131 let buf = PyBuffer::get(py, &data)?;
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
132 let len = buf.item_count();
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
133
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
134 // Build a slice from the mmap'ed buffer data
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
135 let cbuf = buf.buf_ptr();
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
136 let bytes = if std::mem::size_of::<u8>() == buf.item_size()
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
137 && buf.is_c_contiguous()
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
138 && u8::is_compatible_format(buf.format())
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
139 {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
140 unsafe { std::slice::from_raw_parts(cbuf as *const u8, len) }
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
141 } else {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
142 return Err(PyErr::new::<ValueError, _>(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
143 py,
52175
c90e0f65896e rust-revlog: generalize an error message
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52174
diff changeset
144 "buffer has an invalid memory representation".to_string(),
51184
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
145 ));
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
146 };
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
147
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
148 Ok((buf, Box::new(bytes)))
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
149 }
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
150
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
151 fn py_tuple_to_revision_data_params(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
152 py: Python,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
153 tuple: PyTuple,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
154 ) -> PyResult<RevisionDataParams> {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
155 if tuple.len(py) < 8 {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
156 // this is better than the panic promised by tup.get_item()
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
157 return Err(PyErr::new::<IndexError, _>(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
158 py,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
159 "tuple index out of range",
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
160 ));
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
161 }
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
162 let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
163 let node_id = tuple
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
164 .get_item(py, 7)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
165 .extract::<PyBytes>(py)?
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
166 .data(py)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
167 .try_into()
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
168 .expect("nodeid should be set");
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
169 let flags = (offset_or_flags & 0xFFFF) as u16;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
170 let data_offset = offset_or_flags >> 16;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
171 Ok(RevisionDataParams {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
172 flags,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
173 data_offset,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
174 data_compressed_length: tuple.get_item(py, 1).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
175 data_uncompressed_length: tuple.get_item(py, 2).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
176 data_delta_base: tuple.get_item(py, 3).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
177 link_rev: tuple.get_item(py, 4).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
178 parent_rev_1: tuple.get_item(py, 5).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
179 parent_rev_2: tuple.get_item(py, 6).extract(py)?,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
180 node_id,
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
181 ..Default::default()
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
182 })
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
183 }
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
184 fn revision_data_params_to_py_tuple(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
185 py: Python,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
186 params: RevisionDataParams,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
187 ) -> PyTuple {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
188 PyTuple::new(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
189 py,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
190 &[
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
191 params.data_offset.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
192 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
193 .data_compressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
194 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
195 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
196 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
197 .data_uncompressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
198 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
199 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
200 params.data_delta_base.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
201 params.link_rev.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
202 params.parent_rev_1.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
203 params.parent_rev_2.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
204 PyBytes::new(py, &params.node_id)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
205 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
206 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
207 params._sidedata_offset.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
208 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
209 ._sidedata_compressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
210 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
211 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
212 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
213 .data_compression_mode
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
214 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
215 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
216 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
217 ._sidedata_compression_mode
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
218 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
219 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
220 params._rank.into_py_object(py).into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
221 ],
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
222 )
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
223 }
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
224
51209
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
225 struct PySnapshotsCache<'p> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
226 py: Python<'p>,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
227 dict: PyDict,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
228 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
229
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
230 impl<'p> SnapshotsCache for PySnapshotsCache<'p> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
231 fn insert_for(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
232 &mut self,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
233 rev: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
234 value: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
235 ) -> Result<(), RevlogError> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
236 let pyvalue = value.into_py_object(self.py).into_object();
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
237 match self.dict.get_item(self.py, rev) {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
238 Some(obj) => obj
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
239 .extract::<PySet>(self.py)
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
240 .and_then(|set| set.add(self.py, pyvalue)),
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
241 None => PySet::new(self.py, vec![pyvalue])
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
242 .and_then(|set| self.dict.set_item(self.py, rev, set)),
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
243 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
244 .map_err(|_| {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
245 RevlogError::Other(HgError::unsupported(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
246 "Error in Python caches handling",
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
247 ))
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
248 })
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
249 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
250 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
251
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
252 // There are no static generics in Rust (because their implementation is hard,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
253 // I'm guessing it's due to different compilation stages, etc.).
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
254 // So manually generate all three caches and use them in `with_filelog_cache`.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
255 static DELTA_CONFIG_CACHE: OnceLock<(PyObject, RevlogDeltaConfig)> =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
256 OnceLock::new();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
257 static DATA_CONFIG_CACHE: OnceLock<(PyObject, RevlogDataConfig)> =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
258 OnceLock::new();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
259 static FEATURE_CONFIG_CACHE: OnceLock<(PyObject, RevlogFeatureConfig)> =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
260 OnceLock::new();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
261
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
262 /// Cache the first conversion from Python -> Rust config for all filelogs to
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
263 /// save on conversion time when called in a loop.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
264 fn with_filelog_cache<T: Copy>(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
265 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
266 py_config: &PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
267 revlog_type: RevlogType,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
268 cache: &OnceLock<(PyObject, T)>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
269 callback: impl Fn() -> PyResult<T>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
270 ) -> PyResult<T> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
271 let mut was_cached = false;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
272 if revlog_type == RevlogType::Filelog {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
273 if let Some((cached_py_config, rust_config)) = cache.get() {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
274 was_cached = true;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
275 // All filelogs in a given repository *most likely* have the
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
276 // exact same config, but it's not impossible that some extensions
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
277 // do some magic with configs or that this code will be used
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
278 // for longer-running processes. So compare the source `PyObject`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
279 // in case the source changed, at the cost of some overhead.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
280 // We can't use `py_config.eq(cached_py_config)` because all config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
281 // objects are different in Python and `a is b` is false.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
282 if py_config.compare(py, cached_py_config)?.is_eq() {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
283 return Ok(*rust_config);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
284 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
285 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
286 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
287 let config = callback()?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
288 // Do not call the lock unnecessarily if it's already been set.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
289 if !was_cached && revlog_type == RevlogType::Filelog {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
290 cache.set((py_config.clone_ref(py), config)).ok();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
291 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
292 Ok(config)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
293 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
294
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
295 fn extract_delta_config(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
296 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
297 py_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
298 revlog_type: RevlogType,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
299 ) -> PyResult<RevlogDeltaConfig> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
300 let get_delta_config = || {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
301 let max_deltachain_span = py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
302 .getattr(py, "max_deltachain_span")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
303 .extract::<i64>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
304
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
305 let revlog_delta_config = RevlogDeltaConfig {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
306 general_delta: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
307 .getattr(py, "general_delta")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
308 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
309 sparse_revlog: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
310 .getattr(py, "sparse_revlog")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
311 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
312 max_chain_len: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
313 .getattr(py, "max_chain_len")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
314 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
315 max_deltachain_span: if max_deltachain_span < 0 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
316 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
317 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
318 Some(max_deltachain_span as u64)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
319 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
320 upper_bound_comp: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
321 .getattr(py, "upper_bound_comp")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
322 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
323 delta_both_parents: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
324 .getattr(py, "delta_both_parents")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
325 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
326 candidate_group_chunk_size: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
327 .getattr(py, "candidate_group_chunk_size")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
328 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
329 debug_delta: py_config.getattr(py, "debug_delta")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
330 lazy_delta: py_config.getattr(py, "lazy_delta")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
331 lazy_delta_base: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
332 .getattr(py, "lazy_delta_base")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
333 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
334 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
335 Ok(revlog_delta_config)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
336 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
337 with_filelog_cache(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
338 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
339 &py_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
340 revlog_type,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
341 &DELTA_CONFIG_CACHE,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
342 get_delta_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
343 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
344 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
345
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
346 fn extract_data_config(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
347 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
348 py_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
349 revlog_type: RevlogType,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
350 ) -> PyResult<RevlogDataConfig> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
351 let get_data_config = || {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
352 Ok(RevlogDataConfig {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
353 try_pending: py_config.getattr(py, "try_pending")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
354 try_split: py_config.getattr(py, "try_split")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
355 check_ambig: py_config.getattr(py, "check_ambig")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
356 mmap_large_index: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
357 .getattr(py, "mmap_large_index")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
358 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
359 mmap_index_threshold: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
360 .getattr(py, "mmap_index_threshold")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
361 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
362 chunk_cache_size: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
363 .getattr(py, "chunk_cache_size")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
364 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
365 uncompressed_cache_factor: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
366 .getattr(py, "uncompressed_cache_factor")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
367 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
368 uncompressed_cache_count: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
369 .getattr(py, "uncompressed_cache_count")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
370 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
371 with_sparse_read: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
372 .getattr(py, "with_sparse_read")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
373 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
374 sr_density_threshold: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
375 .getattr(py, "sr_density_threshold")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
376 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
377 sr_min_gap_size: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
378 .getattr(py, "sr_min_gap_size")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
379 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
380 general_delta: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
381 .getattr(py, "generaldelta")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
382 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
383 })
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
384 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
385
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
386 with_filelog_cache(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
387 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
388 &py_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
389 revlog_type,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
390 &DATA_CONFIG_CACHE,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
391 get_data_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
392 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
393 }
51187
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51184
diff changeset
394
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
395 fn extract_feature_config(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
396 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
397 py_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
398 revlog_type: RevlogType,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
399 ) -> PyResult<RevlogFeatureConfig> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
400 let get_feature_config = || {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
401 let engine_bytes = &py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
402 .getattr(py, "compression_engine")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
403 .extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
404 let compression_engine = engine_bytes.data(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
405 let compression_engine = match compression_engine {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
406 b"zlib" => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
407 let compression_options = &py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
408 .getattr(py, "compression_engine_options")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
409 .extract::<PyDict>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
410 let zlib_level = compression_options
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
411 .get_item(py, PyBytes::new(py, &b"zlib.level"[..]));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
412 let level = if let Some(level) = zlib_level {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
413 if level.is_none(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
414 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
415 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
416 Some(level.extract(py)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
417 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
418 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
419 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
420 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
421 let mut engine = CompressionConfig::default();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
422 if let Some(level) = level {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
423 engine
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
424 .set_level(level)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
425 .expect("invalid compression level from Python");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
426 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
427 engine
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
428 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
429 b"zstd" => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
430 let compression_options = &py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
431 .getattr(py, "compression_engine_options")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
432 .extract::<PyDict>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
433 let zstd_level = compression_options
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
434 .get_item(py, PyBytes::new(py, &b"zstd.level"[..]));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
435 let level = if let Some(level) = zstd_level {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
436 if level.is_none(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
437 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
438 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
439 Some(level.extract(py)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
440 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
441 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
442 let level = compression_options
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
443 .get_item(py, PyBytes::new(py, &b"level"[..]));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
444 if let Some(level) = level {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
445 if level.is_none(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
446 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
447 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
448 Some(level.extract(py)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
449 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
450 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
451 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
452 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
453 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
454 CompressionConfig::zstd(level)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
455 .expect("invalid compression level from Python")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
456 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
457 b"none" => CompressionConfig::None,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
458 e => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
459 return Err(PyErr::new::<ValueError, _>(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
460 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
461 format!(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
462 "invalid compression engine {}",
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
463 String::from_utf8_lossy(e)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
464 ),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
465 ))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
466 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
467 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
468 let revlog_feature_config = RevlogFeatureConfig {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
469 compression_engine,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
470 censorable: py_config.getattr(py, "censorable")?.extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
471 has_side_data: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
472 .getattr(py, "has_side_data")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
473 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
474 compute_rank: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
475 .getattr(py, "compute_rank")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
476 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
477 canonical_parent_order: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
478 .getattr(py, "canonical_parent_order")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
479 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
480 enable_ellipsis: py_config
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
481 .getattr(py, "enable_ellipsis")?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
482 .extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
483 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
484 Ok(revlog_feature_config)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
485 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
486 with_filelog_cache(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
487 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
488 &py_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
489 revlog_type,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
490 &FEATURE_CONFIG_CACHE,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
491 get_feature_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
492 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
493 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
494
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
495 fn revlog_error_from_msg(py: Python, e: impl ToString) -> PyErr {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
496 let msg = e.to_string();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
497
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
498 match py
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
499 .import("mercurial.error")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
500 .and_then(|m| m.get(py, "RevlogError"))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
501 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
502 Err(e) => e,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
503 Ok(cls) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
504 let msg = PyBytes::new(py, msg.as_bytes());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
505 PyErr::from_instance(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
506 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
507 cls.call(py, (msg,), None).ok().into_py_object(py),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
508 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
509 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
510 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
511 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
512
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
513 py_class!(pub class ReadingContextManager |py| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
514 data inner_revlog: RefCell<InnerRevlog>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
515
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
516 def __enter__(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
517 let res = self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
518 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
519 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
520 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
521 .enter_reading_context()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
522 .map_err(|e| revlog_error_from_msg(py, e));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
523 if let Err(e) = res {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
524 // `__exit__` is not called from Python if `__enter__` fails
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
525 self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
526 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
527 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
528 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
529 .exit_reading_context();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
530 return Err(e)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
531 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
532 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
533 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
534
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
535 def __exit__(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
536 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
537 ty: Option<PyType>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
538 value: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
539 traceback: PyObject
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
540 ) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
541 // unused arguments, keep clippy from complaining without adding
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
542 // a general rule
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
543 let _ = ty;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
544 let _ = value;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
545 let _ = traceback;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
546
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
547 self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
548 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
549 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
550 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
551 .exit_reading_context();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
552 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
553 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
554 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
555
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
556 // Only used from Python *tests*
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
557 py_class!(pub class PyFileHandle |py| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
558 data inner_file: RefCell<std::os::fd::RawFd>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
559
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
560 def tell(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
561 let locals = PyDict::new(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
562 locals.set_item(py, "os", py.import("os")?)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
563 locals.set_item(py, "fd", *self.inner_file(py).borrow())?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
564 let f = py.eval("os.fdopen(fd)", None, Some(&locals))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
565
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
566 // Prevent Python from closing the file after garbage collecting.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
567 // This is fine since Rust is still holding on to the actual File.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
568 // (and also because it's only used in tests).
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
569 std::mem::forget(f.clone_ref(py));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
570
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
571 locals.set_item(py, "f", f)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
572 let res = py.eval("f.tell()", None, Some(&locals))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
573 Ok(res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
574 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
575 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
576
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
577 /// Wrapper around a Python transaction object, to keep `hg-core` oblivious
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
578 /// of the fact it's being called from Python.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
579 pub struct PyTransaction {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
580 inner: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
581 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
582
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
583 impl PyTransaction {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
584 pub fn new(inner: PyObject) -> Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
585 Self { inner }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
586 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
587 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
588
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
589 impl Clone for PyTransaction {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
590 fn clone(&self) -> Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
591 let gil = &Python::acquire_gil();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
592 let py = gil.python();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
593 Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
594 inner: self.inner.clone_ref(py),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
595 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
596 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
597 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
598
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
599 impl Transaction for PyTransaction {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
600 fn add(&mut self, file: impl AsRef<std::path::Path>, offset: usize) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
601 let gil = &Python::acquire_gil();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
602 let py = gil.python();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
603 let file = PyBytes::new(py, &get_bytes_from_path(file.as_ref()));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
604 self.inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
605 .call_method(py, "add", (file, offset), None)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
606 .expect("transaction add failed");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
607 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
608 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
609
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
610 py_class!(pub class WritingContextManager |py| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
611 data inner_revlog: RefCell<InnerRevlog>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
612 data transaction: RefCell<PyTransaction>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
613 data data_end: Cell<Option<usize>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
614
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
615 def __enter__(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
616 let res = self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
617 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
618 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
619 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
620 .enter_writing_context(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
621 self.data_end(py).get(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
622 &mut *self.transaction(py).borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
623 ).map_err(|e| revlog_error_from_msg(py, e));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
624 if let Err(e) = res {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
625 // `__exit__` is not called from Python if `__enter__` fails
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
626 self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
627 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
628 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
629 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
630 .exit_writing_context();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
631 return Err(e)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
632 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
633 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
634 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
635
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
636 def __exit__(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
637 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
638 ty: Option<PyType>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
639 value: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
640 traceback: PyObject
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
641 ) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
642 // unused arguments, keep clippy from complaining without adding
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
643 // a general rule
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
644 let _ = ty;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
645 let _ = value;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
646 let _ = traceback;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
647
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
648 self.inner_revlog(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
649 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
650 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
651 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
652 .exit_writing_context();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
653 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
654 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
655 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
656
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
657 struct PyFnCache {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
658 fncache: PyObject,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
659 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
660 impl PyFnCache {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
661 fn new(fncache: PyObject) -> Self {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
662 Self { fncache }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
663 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
664 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
665
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
666 impl Clone for PyFnCache {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
667 fn clone(&self) -> Self {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
668 let gil = Python::acquire_gil();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
669 let py = gil.python();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
670 Self {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
671 fncache: self.fncache.clone_ref(py),
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
672 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
673 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
674 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
675
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
676 /// Cache whether the fncache is loaded to avoid Python round-trip every time.
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
677 /// Once the fncache is loaded, it stays loaded unless we're in a very
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
678 /// long-running process, none of which we actually support for now.
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
679 static FN_CACHE_IS_LOADED: AtomicBool = AtomicBool::new(false);
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
680
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
681 impl FnCache for PyFnCache {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
682 fn is_loaded(&self) -> bool {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
683 if FN_CACHE_IS_LOADED.load(Ordering::Relaxed) {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
684 return true;
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
685 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
686 let gil = Python::acquire_gil();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
687 let py = gil.python();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
688 // TODO raise in case of error?
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
689 let is_loaded = self
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
690 .fncache
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
691 .getattr(py, "is_loaded")
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
692 .ok()
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
693 .map(|o| {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
694 o.extract::<bool>(py)
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
695 .expect("is_loaded returned something other than a bool")
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
696 })
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
697 .unwrap_or(false);
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
698 if is_loaded {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
699 FN_CACHE_IS_LOADED.store(true, Ordering::Relaxed);
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
700 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
701 is_loaded
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
702 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
703 fn add(&self, path: &std::path::Path) {
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
704 let gil = Python::acquire_gil();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
705 let py = gil.python();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
706 // TODO raise in case of error?
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
707 self.fncache
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
708 .call_method(
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
709 py,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
710 "add",
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
711 (PyBytes::new(py, &get_bytes_from_path(path)),),
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
712 None,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
713 )
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
714 .ok();
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
715 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
716 }
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
717
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
718 py_class!(pub class InnerRevlog |py| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
719 @shared data inner: CoreInnerRevlog;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
720 data nt: RefCell<Option<CoreNodeTree>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
721 data docket: RefCell<Option<PyObject>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
722 // Holds a reference to the mmap'ed persistent nodemap data
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
723 data nodemap_mmap: RefCell<Option<PyBuffer>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
724 // Holds a reference to the mmap'ed persistent index data
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
725 data index_mmap: RefCell<PyBuffer>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
726 data head_revs_py_list: RefCell<Option<PyList>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
727 data head_node_ids_py_list: RefCell<Option<PyList>>;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
728 data revision_cache: RefCell<Option<PyObject>>;
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
729 data use_persistent_nodemap: bool;
52176
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
730 data nodemap_queries: AtomicUsize;
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
731
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
732 def __new__(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
733 _cls,
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
734 vfs_base: PyObject,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
735 fncache: PyObject,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
736 vfs_is_readonly: bool,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
737 index_data: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
738 index_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
739 data_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
740 sidedata_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
741 inline: bool,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
742 data_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
743 delta_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
744 feature_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
745 chunk_cache: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
746 default_compression_header: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
747 revlog_type: usize,
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
748 use_persistent_nodemap: bool,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
749 ) -> PyResult<Self> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
750 Self::inner_new(
44503
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
751 py,
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
752 vfs_base,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
753 fncache,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
754 vfs_is_readonly,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
755 index_data,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
756 index_file,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
757 data_file,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
758 sidedata_file,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
759 inline,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
760 data_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
761 delta_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
762 feature_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
763 chunk_cache,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
764 default_compression_header,
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
765 revlog_type,
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
766 use_persistent_nodemap
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
767 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
768 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
769
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
770 def clear_cache(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
771 assert!(!self.is_delaying(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
772 self.revision_cache(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
773 self.inner(py).borrow_mut().clear_cache();
52176
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
774 self.nodemap_queries(py).store(0, Ordering::Relaxed);
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
775 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
776 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
777
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
778 @property def canonical_index_file(&self) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
779 let path = self.inner(py).borrow().canonical_index_file();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
780 Ok(PyBytes::new(py, &get_bytes_from_path(path)))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
781 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
782
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
783 @property def is_delaying(&self) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
784 Ok(self.inner(py).borrow().is_delaying())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
785 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
786
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
787 @property def _revisioncache(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
788 let cache = &*self.revision_cache(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
789 match cache {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
790 None => Ok(py.None()),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
791 Some(cache) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
792 Ok(cache.clone_ref(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
793 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
794 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
795
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
796 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
797
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
798 @property def _writinghandles(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
799 use std::os::fd::AsRawFd;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
800
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
801 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
802 let handles = inner.python_writing_handles();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
803
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
804 match handles.as_ref() {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
805 None => Ok(py.None()),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
806 Some(handles) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
807 let d_handle = if let Some(d_handle) = &handles.data_handle {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
808 let handle = RefCell::new(d_handle.file.as_raw_fd());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
809 Some(PyFileHandle::create_instance(py, handle)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
810 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
811 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
812 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
813 let handle =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
814 RefCell::new(handles.index_handle.file.as_raw_fd());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
815 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
816 (
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
817 PyFileHandle::create_instance(py, handle)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
818 d_handle,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
819 py.None(), // Sidedata handle
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
820
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
821 ).to_py_object(py).into_object()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
822 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
823 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
824 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
825
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
826 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
827
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
828 @_revisioncache.setter def set_revision_cache(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
829 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
830 value: Option<PyObject>
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
831 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
832 *self.revision_cache(py).borrow_mut() = value.clone_ref(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
833 match value {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
834 None => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
835 // This means the property has been deleted, *not* that the
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
836 // property has been set to `None`. Whatever happens is up
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
837 // to the implementation. Here we just set it to `None`.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
838 self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
839 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
840 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
841 .last_revision_cache
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
842 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
843 .expect("lock should not be held")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
844 .take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
845 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
846 Some(tuple) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
847 if tuple.is_none(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
848 self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
849 .inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
850 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
851 .last_revision_cache
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
852 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
853 .expect("lock should not be held")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
854 .take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
855 return Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
856 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
857 let node = tuple.get_item(py, 0)?.extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
858 let node = node_from_py_bytes(py, &node)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
859 let rev = tuple.get_item(py, 1)?.extract::<BaseRevision>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
860 // Ok because Python only sets this if the revision has been
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
861 // checked
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
862 let rev = Revision(rev);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
863 let data = tuple.get_item(py, 2)?.extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
864 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
865 let mut last_revision_cache = inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
866 .last_revision_cache
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
867 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
868 .expect("lock should not be held");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
869 *last_revision_cache =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
870 Some((node, rev, Box::new(PyBytesDeref::new(py, data))));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
871 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
872 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
873 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
874 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
875
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
876 @property def inline(&self) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
877 Ok(self.inner(py).borrow().is_inline())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
878 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
879
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
880 @inline.setter def set_inline(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
881 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
882 value: Option<PyObject>
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
883 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
884 if let Some(v) = value {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
885 self.inner(py).borrow_mut().inline = v.extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
886 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
887 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
888 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
889
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
890 @property def index_file(&self) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
891 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
892 PyBytes::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
893 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
894 &get_bytes_from_path(&self.inner(py).borrow().index_file)
51236
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
895 )
44503
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
896 )
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
897 }
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
898
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
899 @index_file.setter def set_index_file(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
900 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
901 value: Option<PyObject>
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
902 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
903 let path = get_path_from_bytes(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
904 value
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
905 .expect("don't delete the index path")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
906 .extract::<PyBytes>(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
907 .data(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
908 ).to_owned();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
909 self.inner(py).borrow_mut().index_file = path;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
910 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
911 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
912
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
913 @property def is_writing(&self) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
914 Ok(self.inner(py).borrow().is_writing())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
915 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
916
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
917 @property def is_open(&self) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
918 Ok(self.inner(py).borrow().is_open())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
919 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
920
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
921 def issnapshot(&self, rev: PyRevision) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
922 self.inner_issnapshot(py, UncheckedRevision(rev.0))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
923 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
924
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
925 def _deltachain(&self, *args, **kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
926 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
927 let general_delta = inner.index.uses_generaldelta();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
928 let args = PyTuple::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
929 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
930 &[
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
931 args.get_item(py, 0),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
932 kw.and_then(|d| d.get_item(py, "stoprev")).to_py_object(py),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
933 general_delta.to_py_object(py).into_object(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
934 ]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
935 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
936 self._index_deltachain(py, &args, kw)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
937 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
938
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
939 def compress(&self, data: PyObject) -> PyResult<PyTuple> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
940 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
941 let py_buffer = PyBuffer::get(py, &data)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
942 let deref = PyBufferDeref::new(py, py_buffer)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
943 let compressed = inner.compress(&deref)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
944 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
945 let compressed = compressed.as_deref();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
946 let header = if compressed.is_some() {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
947 PyBytes::new(py, &b""[..])
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
948 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
949 PyBytes::new(py, &b"u"[..])
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
950 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
951 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
952 (
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
953 header,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
954 PyBytes::new(py, compressed.unwrap_or(&deref))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
955 ).to_py_object(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
956 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
957 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
958
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
959 def reading(&self) -> PyResult<ReadingContextManager> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
960 ReadingContextManager::create_instance(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
961 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
962 RefCell::new(self.clone_ref(py)),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
963 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
964 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
965
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
966 def writing(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
967 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
968 transaction: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
969 data_end: Option<usize>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
970 sidedata_end: Option<usize>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
971 ) -> PyResult<WritingContextManager> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
972 // Silence unused argument (only relevant for changelog v2)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
973 let _ = sidedata_end;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
974 WritingContextManager::create_instance(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
975 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
976 RefCell::new(self.clone_ref(py)),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
977 RefCell::new(PyTransaction::new(transaction)),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
978 Cell::new(data_end)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
979 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
980 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
981
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
982 def split_inline(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
983 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
984 _tr: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
985 header: i32,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
986 new_index_file_path: Option<PyObject>
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
987 ) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
988 let mut inner = self.inner(py).borrow_mut();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
989 let new_index_file_path = match new_index_file_path {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
990 Some(path) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
991 let path = path.extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
992 Some(get_path_from_bytes(path.data(py)).to_owned())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
993 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
994 None => None,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
995 };
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
996 let header = IndexHeader::parse(&header.to_be_bytes());
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
997 let header = header.expect("invalid header bytes");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
998 let path = inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
999 .split_inline(header, new_index_file_path)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1000 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1001 Ok(PyBytes::new(py, &get_bytes_from_path(path)))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1002 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1003
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1004 def get_segment_for_revs(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1005 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1006 startrev: PyRevision,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1007 endrev: PyRevision,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1008 ) -> PyResult<PyTuple> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1009 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1010 let (offset, data) = inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1011 .get_segment_for_revs(Revision(startrev.0), Revision(endrev.0))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1012 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1013 let data = PyBytes::new(py, &data);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1014 Ok((offset, data).to_py_object(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1015 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1016
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1017 def raw_text(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1018 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1019 _node: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1020 rev: PyRevision
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1021 ) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1022 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1023 let mut py_bytes = PyBytes::new(py, &[]);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1024 inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1025 .raw_text(Revision(rev.0), |size, f| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1026 py_bytes = with_pybytes_buffer(py, size, f)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1027 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1028 }).map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1029 Ok(py_bytes)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1030 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1031
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1032 def _chunk(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1033 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1034 rev: PyRevision,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1035 ) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1036 let inner = self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1037 let chunk = inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1038 .chunk_for_rev(Revision(rev.0))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1039 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1040 let chunk = PyBytes::new(py, &chunk);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1041 Ok(chunk)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1042 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1043
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1044 def write_entry(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1045 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1046 transaction: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1047 entry: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1048 data: PyTuple,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1049 _link: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1050 offset: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1051 _sidedata: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1052 _sidedata_offset: PyInt,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1053 index_end: Option<u64>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1054 data_end: Option<u64>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1055 _sidedata_end: Option<PyInt>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1056 ) -> PyResult<PyTuple> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1057 let mut inner = self.inner(py).borrow_mut();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1058 let transaction = PyTransaction::new(transaction);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1059 let py_bytes = entry.extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1060 let entry = PyBytesDeref::new(py, py_bytes);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1061 let header = data.get_item(py, 0).extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1062 let header = header.data(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1063 let data = data.get_item(py, 1);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1064 let py_bytes = data.extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1065 let data = PyBytesDeref::new(py, py_bytes);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1066 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1067 inner.write_entry(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1068 transaction,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1069 &entry,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1070 (header, &data),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1071 offset,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1072 index_end,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1073 data_end
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1074 ).map_err(|e| revlog_error_from_msg(py, e))?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1075 .to_py_object(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1076 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1077 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1078
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1079 def delay(&self) -> PyResult<Option<PyBytes>> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1080 let path = self.inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1081 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1082 .delay()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1083 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1084 Ok(path.map(|p| PyBytes::new(py, &get_bytes_from_path(p))))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1085 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1086
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1087 def write_pending(&self) -> PyResult<PyTuple> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1088 let (path, any_pending) = self.inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1089 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1090 .write_pending()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1091 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1092 let maybe_path = match path {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1093 Some(path) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1094 PyBytes::new(py, &get_bytes_from_path(path)).into_object()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1095 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1096 None => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1097 py.None()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1098 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1099 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1100 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1101 (
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1102 maybe_path,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1103 any_pending
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1104 ).to_py_object(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1105 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1106 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1107
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1108 def finalize_pending(&self) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1109 let path = self.inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1110 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1111 .finalize_pending()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1112 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1113 Ok(PyBytes::new(py, &get_bytes_from_path(path)))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1114 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1115
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1116 // -- forwarded index methods --
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1117
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1118 def _index_get_rev(&self, node: PyBytes) -> PyResult<Option<PyRevision>> {
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1119 let node = node_from_py_bytes(py, &node)?;
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1120 // Filelogs have no persistent nodemaps and are often small, use a
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1121 // brute force lookup from the end backwards. If there is a very large
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1122 // filelog (automation file that changes every commit etc.), it also
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1123 // seems to work quite well for all measured purposes so far.
52176
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
1124 let mut nodemap_queries =
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
1125 self.nodemap_queries(py).fetch_add(1, Ordering::Relaxed);
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
1126 // Still need to add since `fetch_add` returns the old value
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
1127 nodemap_queries += 1;
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
1128 if !*self.use_persistent_nodemap(py) && nodemap_queries <= 4 {
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1129 let idx = &self.inner(py).borrow().index;
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1130 let res =
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1131 idx.rev_from_node_no_persistent_nodemap(node.into()).ok();
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1132 return Ok(res.map(Into::into))
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1133 }
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1134 let opt = self.get_nodetree(py)?.borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1135 let nt = opt.as_ref().expect("nodetree should be set");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1136 let ridx = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1137 let rust_rev =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1138 nt.find_bin(ridx, node.into()).map_err(|e| nodemap_error(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1139 Ok(rust_rev.map(Into::into))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1140 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1141
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1142 /// same as `_index_get_rev()` but raises a bare `error.RevlogError` if node
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1143 /// is not found.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1144 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1145 /// No need to repeat `node` in the exception, `mercurial/revlog.py`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1146 /// will catch and rewrap with it
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1147 def _index_rev(&self, node: PyBytes) -> PyResult<PyRevision> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1148 self._index_get_rev(py, node)?.ok_or_else(|| revlog_error(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1149 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1150
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1151 /// return True if the node exist in the index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1152 def _index_has_node(&self, node: PyBytes) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1153 // TODO OPTIM we could avoid a needless conversion here,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1154 // to do when scaffolding for pure Rust switch is removed,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1155 // as `_index_get_rev()` currently does the necessary assertions
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1156 self._index_get_rev(py, node).map(|opt| opt.is_some())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1157 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1158
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1159 /// find length of shortest hex nodeid of a binary ID
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1160 def _index_shortest(&self, node: PyBytes) -> PyResult<usize> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1161 let opt = self.get_nodetree(py)?.borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1162 let nt = opt.as_ref().expect("nodetree should be set");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1163 let idx = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1164 match nt.unique_prefix_len_node(idx, &node_from_py_bytes(py, &node)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1165 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1166 Ok(Some(l)) => Ok(l),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1167 Ok(None) => Err(revlog_error(py)),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1168 Err(e) => Err(nodemap_error(py, e)),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1169 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1170 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1171
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1172 def _index_partialmatch(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1173 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1174 node: PyObject
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1175 ) -> PyResult<Option<PyBytes>> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1176 let opt = self.get_nodetree(py)?.borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1177 let nt = opt.as_ref().expect("nodetree should be set");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1178 let idx = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1179
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1180 let node = node.extract::<PyBytes>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1181 let node_as_string = String::from_utf8_lossy(node.data(py));
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1182
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1183 let prefix = NodePrefix::from_hex(node_as_string.to_string())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1184 .map_err(|_| PyErr::new::<ValueError, _>(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1185 py, format!("Invalid node or prefix '{}'", node_as_string))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1186 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1187
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1188 nt.find_bin(idx, prefix)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1189 // TODO make an inner API returning the node directly
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1190 .map(|opt| opt.map(|rev| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1191 PyBytes::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1192 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1193 idx.node(rev).expect("node should exist").as_bytes()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1194 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1195 }))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1196 .map_err(|e| nodemap_error(py, e))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1197
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1198 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1199
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1200 /// append an index entry
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1201 def _index_append(&self, tup: PyTuple) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1202 if tup.len(py) < 8 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1203 // this is better than the panic promised by tup.get_item()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1204 return Err(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1205 PyErr::new::<IndexError, _>(py, "tuple index out of range"))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1206 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1207 let node_bytes = tup.get_item(py, 7).extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1208 let node = node_from_py_object(py, &node_bytes)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1209
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1210 let rev = self.len(py)? as BaseRevision;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1211
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1212 // This is ok since we will just add the revision to the index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1213 let rev = Revision(rev);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1214 self.inner(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1215 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1216 .index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1217 .append(py_tuple_to_revision_data_params(py, tup)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1218 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1219 let idx = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1220 self.get_nodetree(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1221 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1222 .as_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1223 .expect("nodetree should be set")
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1224 .insert(idx, &node, rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1225 .map_err(|e| nodemap_error(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1226 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1227 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1228
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1229 def _index___delitem__(&self, key: PyObject) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1230 // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1231 let start = if let Ok(rev) = key.extract(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1232 UncheckedRevision(rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1233 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1234 let start = key.getattr(py, "start")?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1235 UncheckedRevision(start.extract(py)?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1236 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1237 let mut borrow = self.inner(py).borrow_mut();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1238 let start = borrow
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1239 .index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1240 .check_revision(start)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1241 .ok_or_else(|| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1242 nodemap_error(py, NodeMapError::RevisionNotInIndex(start))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1243 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1244 borrow.index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1245 .remove(start)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1246 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1247 drop(borrow);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1248 let mut opt = self.get_nodetree(py)?.borrow_mut();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1249 let nt = opt.as_mut().expect("nodetree should be set");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1250 nt.invalidate_all();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1251 self.fill_nodemap(py, nt)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1252 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1253 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1254
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1255 /// return the gca set of the given revs
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1256 def _index_ancestors(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1257 let rust_res = self.inner_ancestors(py, args)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1258 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1259 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1260
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1261 /// return the heads of the common ancestors of the given revs
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1262 def _index_commonancestorsheads(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1263 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1264 *args,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1265 **_kw
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1266 ) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1267 let rust_res = self.inner_commonancestorsheads(py, args)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1268 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1269 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1270
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1271 /// Clear the index caches and inner py_class data.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1272 /// It is Python's responsibility to call `update_nodemap_data` again.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1273 def _index_clearcaches(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1274 self.nt(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1275 self.docket(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1276 self.nodemap_mmap(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1277 self.head_revs_py_list(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1278 self.head_node_ids_py_list(py).borrow_mut().take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1279 self.inner(py).borrow_mut().index.clear_caches();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1280 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1281 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1282
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1283 /// return the raw binary string representing a revision
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1284 def _index_entry_binary(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1285 let rindex = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1286 let rev = UncheckedRevision(args.get_item(py, 0).extract(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1287 let rust_bytes = rindex.check_revision(rev).and_then(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1288 |r| rindex.entry_binary(r)).ok_or_else(|| rev_not_in_index(py, rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1289 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1290 let rust_res = PyBytes::new(py, rust_bytes).into_object();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1291 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1292 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1293
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1294
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1295 /// return a binary packed version of the header
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1296 def _index_pack_header(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1297 let rindex = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1298 let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1299 let rust_res = PyBytes::new(py, &packed).into_object();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1300 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1301 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1302
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1303 /// compute phases
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1304 def _index_computephasesmapsets(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1305 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1306 *args,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1307 **_kw
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1308 ) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1309 let py_roots = args.get_item(py, 0).extract::<PyDict>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1310 let rust_res = self.inner_computephasesmapsets(py, py_roots)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1311 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1312 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1313
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1314 /// reachableroots
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1315 def _index_reachableroots2(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1316 let rust_res = self.inner_reachableroots2(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1317 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1318 UncheckedRevision(args.get_item(py, 0).extract(py)?),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1319 args.get_item(py, 1),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1320 args.get_item(py, 2),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1321 args.get_item(py, 3).extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1322 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1323 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1324 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1325
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1326 /// get head revisions
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1327 def _index_headrevs(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1328 let (filtered_revs, stop_rev) = match &args.len(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1329 0 => Ok((py.None(), py.None())),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1330 1 => Ok((args.get_item(py, 0), py.None())),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1331 2 => Ok((args.get_item(py, 0), args.get_item(py, 1))),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1332 _ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1333 }?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1334 self.inner_headrevs(py, &filtered_revs, &stop_rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1335 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1336
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1337 /// get head nodeids
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1338 def _index_head_node_ids(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1339 let rust_res = self.inner_head_node_ids(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1340 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1341 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1342
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1343 /// get diff in head revisions
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1344 def _index_headrevsdiff(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1345 let rust_res = self.inner_headrevsdiff(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1346 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1347 &args.get_item(py, 0),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1348 &args.get_item(py, 1))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1349 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1350 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1351
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1352 /// True if the object is a snapshot
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1353 def _index_issnapshot(&self, *args, **_kw) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1354 let rev = UncheckedRevision(args.get_item(py, 0).extract(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1355 self.inner_issnapshot(py, rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1356 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1357
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1358 /// Gather snapshot data in a cache dict
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1359 def _index_findsnapshots(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1360 let index = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1361 let cache: PyDict = args.get_item(py, 0).extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1362 // this methods operates by setting new values in the cache,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1363 // hence we will compare results by letting the C implementation
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1364 // operate over a deepcopy of the cache, and finally compare both
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1365 // caches.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1366 let c_cache = PyDict::new(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1367 for (k, v) in cache.items(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1368 c_cache.set_item(py, k, PySet::new(py, v)?)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1369 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1370
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1371 let start_rev = UncheckedRevision(args.get_item(py, 1).extract(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1372 let end_rev = UncheckedRevision(args.get_item(py, 2).extract(py)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1373 let mut cache_wrapper = PySnapshotsCache{ py, dict: cache };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1374 index.find_snapshots(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1375 start_rev,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1376 end_rev,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1377 &mut cache_wrapper,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1378 ).map_err(|_| revlog_error(py))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1379 Ok(py.None())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1380 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1381
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1382 /// determine revisions with deltas to reconstruct fulltext
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1383 def _index_deltachain(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1384 let index = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1385 let rev = args.get_item(py, 0).extract::<BaseRevision>(py)?.into();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1386 let stop_rev =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1387 args.get_item(py, 1).extract::<Option<BaseRevision>>(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1388 let rev = index.check_revision(rev).ok_or_else(|| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1389 nodemap_error(py, NodeMapError::RevisionNotInIndex(rev))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1390 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1391 let stop_rev = if let Some(stop_rev) = stop_rev {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1392 let stop_rev = UncheckedRevision(stop_rev);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1393 Some(index.check_revision(stop_rev).ok_or_else(|| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1394 nodemap_error(py, NodeMapError::RevisionNotInIndex(stop_rev))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1395 })?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1396 } else {None};
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1397 let using_general_delta = args.get_item(py, 2)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1398 .extract::<Option<u32>>(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1399 .map(|i| i != 0);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1400 let (chain, stopped) = index.delta_chain(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1401 rev, stop_rev, using_general_delta
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1402 ).map_err(|e| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1403 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1404 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1405
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1406 let chain: Vec<_> = chain.into_iter().map(|r| r.0).collect();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1407 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1408 PyTuple::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1409 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1410 &[
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1411 chain.into_py_object(py).into_object(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1412 stopped.into_py_object(py).into_object()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1413 ]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1414 ).into_object()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1415 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1416 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1417
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1418 /// slice planned chunk read to reach a density threshold
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1419 def _index_slicechunktodensity(&self, *args, **_kw) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1420 let rust_res = self.inner_slicechunktodensity(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1421 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1422 args.get_item(py, 0),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1423 args.get_item(py, 1).extract(py)?,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1424 args.get_item(py, 2).extract(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1425 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1426 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1427 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1428
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1429 def _index___len__(&self) -> PyResult<usize> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1430 self.len(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1431 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1432
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1433 def _index___getitem__(&self, key: PyObject) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1434 let rust_res = self.inner_getitem(py, key.clone_ref(py))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1435 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1436 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1437
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1438 def _index___contains__(&self, item: PyObject) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1439 // ObjectProtocol does not seem to provide contains(), so
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1440 // this is an equivalent implementation of the index_contains()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1441 // defined in revlog.c
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1442 match item.extract::<i32>(py) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1443 Ok(rev) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1444 Ok(rev >= -1 && rev < self.len(py)? as BaseRevision)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1445 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1446 Err(_) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1447 let item_bytes: PyBytes = item.extract(py)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1448 let rust_res = self._index_has_node(py, item_bytes)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1449 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1450 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1451 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1452 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1453
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1454 def _index_nodemap_data_all(&self) -> PyResult<PyBytes> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1455 self.inner_nodemap_data_all(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1456 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1457
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1458 def _index_nodemap_data_incremental(&self) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1459 self.inner_nodemap_data_incremental(py)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1460 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1461
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1462 def _index_update_nodemap_data(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1463 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1464 docket: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1465 nm_data: PyObject
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1466 ) -> PyResult<PyObject> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1467 self.inner_update_nodemap_data(py, docket, nm_data)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1468 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1469
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1470 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1471 def _index_entry_size(&self) -> PyResult<PyInt> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1472 let rust_res: PyInt = INDEX_ENTRY_SIZE.to_py_object(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1473 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1474 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1475
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1476 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1477 def _index_rust_ext_compat(&self) -> PyResult<PyInt> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1478 // will be entirely removed when the Rust index yet useful to
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1479 // implement in Rust to detangle things when removing `self.cindex`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1480 let rust_res: PyInt = 1.to_py_object(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1481 Ok(rust_res)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1482 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1483
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1484 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1485 def _index_is_rust(&self) -> PyResult<PyBool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1486 Ok(false.to_py_object(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1487 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1488
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1489
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1490 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1491
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1492 /// Forwarded index methods?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1493 impl InnerRevlog {
52411
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1494 pub fn pub_inner<'p, 'a: 'p>(
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1495 &'a self,
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1496 py: Python<'p>,
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1497 ) -> PySharedRef<'p, CoreInnerRevlog> {
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1498 self.inner(py)
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1499 }
c2480ac4c5e2 rust-pyo3: retrieving the InnerRevlog of hg-cpython
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52178
diff changeset
1500
51190
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51189
diff changeset
1501 fn len(&self, py: Python) -> PyResult<usize> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1502 let rust_index_len = self.inner(py).borrow().index.len();
51226
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51222
diff changeset
1503 Ok(rust_index_len)
51190
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51189
diff changeset
1504 }
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1505 /// This is scaffolding at this point, but it could also become
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1506 /// a way to start a persistent nodemap or perform a
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1507 /// vacuum / repack operation
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1508 fn fill_nodemap(
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1509 &self,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1510 py: Python,
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1511 nt: &mut CoreNodeTree,
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1512 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1513 let index = &self.inner(py).borrow().index;
51190
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51189
diff changeset
1514 for r in 0..self.len(py)? {
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1515 let rev = Revision(r as BaseRevision);
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1516 // in this case node() won't ever return None
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1517 nt.insert(index, index.node(rev).expect("node should exist"), rev)
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1518 .map_err(|e| nodemap_error(py, e))?
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1519 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1520 Ok(py.None())
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1521 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1522
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1523 fn get_nodetree<'a>(
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1524 &'a self,
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1525 py: Python<'a>,
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1526 ) -> PyResult<&'a RefCell<Option<CoreNodeTree>>> {
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1527 if self.nt(py).borrow().is_none() {
51117
532e74ad3ff6 rust: run a clippy pass with the latest stable version
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50976
diff changeset
1528 let readonly = Box::<Vec<_>>::default();
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1529 let mut nt = CoreNodeTree::load_bytes(readonly, 0);
44507
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1530 self.fill_nodemap(py, &mut nt)?;
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1531 self.nt(py).borrow_mut().replace(nt);
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1532 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1533 Ok(self.nt(py))
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1534 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1535
44508
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1536 /// Returns the full nodemap bytes to be written as-is to disk
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1537 fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1538 let nodemap = self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1539 .get_nodetree(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1540 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1541 .take()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1542 .expect("nodetree should exist");
44508
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1543 let (readonly, bytes) = nodemap.into_readonly_and_added_bytes();
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1544
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1545 // If there's anything readonly, we need to build the data again from
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1546 // scratch
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1547 let bytes = if readonly.len() > 0 {
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1548 let mut nt = CoreNodeTree::load_bytes(Box::<Vec<_>>::default(), 0);
44508
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1549 self.fill_nodemap(py, &mut nt)?;
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1550
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1551 let (readonly, bytes) = nt.into_readonly_and_added_bytes();
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1552 assert_eq!(readonly.len(), 0);
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1553
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1554 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1555 } else {
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1556 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1557 };
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1558
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1559 let bytes = PyBytes::new(py, &bytes);
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1560 Ok(bytes)
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1561 }
44509
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1562
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1563 /// Returns the last saved docket along with the size of any changed data
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1564 /// (in number of blocks), and said data as bytes.
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1565 fn inner_nodemap_data_incremental(
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1566 &self,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1567 py: Python,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1568 ) -> PyResult<PyObject> {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1569 let docket = self.docket(py).borrow();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1570 let docket = match docket.as_ref() {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1571 Some(d) => d,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1572 None => return Ok(py.None()),
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1573 };
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1574
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1575 let node_tree = self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1576 .get_nodetree(py)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1577 .borrow_mut()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1578 .take()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1579 .expect("nodetree should exist");
44509
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1580 let masked_blocks = node_tree.masked_readonly_blocks();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1581 let (_, data) = node_tree.into_readonly_and_added_bytes();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1582 let changed = masked_blocks * std::mem::size_of::<Block>();
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1583
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1584 Ok((docket, changed, PyBytes::new(py, &data))
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1585 .to_py_object(py)
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1586 .into_object())
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1587 }
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1588
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1589 /// Update the nodemap from the new (mmaped) data.
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1590 /// The docket is kept as a reference for later incremental calls.
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1591 fn inner_update_nodemap_data(
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1592 &self,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1593 py: Python,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1594 docket: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1595 nm_data: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1596 ) -> PyResult<PyObject> {
51184
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
1597 // Safety: we keep the buffer around inside the class as `nodemap_mmap`
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
1598 let (buf, bytes) = unsafe { mmap_keeparound(py, nm_data)? };
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1599 let len = buf.item_count();
51183
8ade5e6cdb61 rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51117
diff changeset
1600 self.nodemap_mmap(py).borrow_mut().replace(buf);
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1601
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1602 let mut nt = CoreNodeTree::load_bytes(bytes, len);
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1603
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1604 let data_tip = docket
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1605 .getattr(py, "tip_rev")?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1606 .extract::<BaseRevision>(py)?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1607 .into();
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1608 self.docket(py).borrow_mut().replace(docket.clone_ref(py));
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1609 let idx = &self.inner(py).borrow().index;
50974
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49914
diff changeset
1610 let data_tip = idx.check_revision(data_tip).ok_or_else(|| {
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49914
diff changeset
1611 nodemap_error(py, NodeMapError::RevisionNotInIndex(data_tip))
1928b770e3e7 rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents: 49914
diff changeset
1612 })?;
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1613 let current_tip = idx.len();
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1614
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1615 for r in (data_tip.0 + 1)..current_tip as BaseRevision {
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1616 let rev = Revision(r);
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1617 // in this case node() won't ever return None
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1618 nt.insert(idx, idx.node(rev).expect("node should exist"), rev)
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1619 .map_err(|e| nodemap_error(py, e))?
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1620 }
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1621
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1622 *self.nt(py).borrow_mut() = Some(nt);
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1623
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1624 Ok(py.None())
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1625 }
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1626
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1627 fn inner_getitem(&self, py: Python, key: PyObject) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1628 let idx = &self.inner(py).borrow().index;
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1629 Ok(match key.extract::<BaseRevision>(py) {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1630 Ok(key_as_int) => {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1631 let entry_params = if key_as_int == NULL_REVISION.0 {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1632 RevisionDataParams::default()
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1633 } else {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1634 let rev = UncheckedRevision(key_as_int);
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1635 match idx.entry_as_params(rev) {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1636 Some(e) => e,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1637 None => {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1638 return Err(PyErr::new::<IndexError, _>(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1639 py,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1640 "revlog index out of range",
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1641 ));
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1642 }
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1643 }
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1644 };
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1645 revision_data_params_to_py_tuple(py, entry_params)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1646 .into_object()
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1647 }
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1648 _ => self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1649 ._index_get_rev(py, key.extract::<PyBytes>(py)?)?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1650 .map_or_else(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1651 || py.None(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1652 |py_rev| py_rev.into_py_object(py).into_object(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1653 ),
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1654 })
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1655 }
51212
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
1656
51259
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1657 fn inner_head_node_ids(&self, py: Python) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1658 let index = &self.inner(py).borrow().index;
51259
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1659
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1660 // We don't use the shortcut here, as it's actually slower to loop
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1661 // through the cached `PyList` than to re-do the whole computation for
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1662 // large lists, which are the performance sensitive ones anyway.
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1663 let head_revs = index.head_revs().map_err(|e| graph_error(py, e))?;
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1664 let res: Vec<_> = head_revs
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1665 .iter()
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1666 .map(|r| {
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1667 PyBytes::new(
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1668 py,
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1669 index
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1670 .node(*r)
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1671 .expect("rev should have been in the index")
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1672 .as_bytes(),
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1673 )
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1674 .into_object()
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1675 })
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1676 .collect();
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1677
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1678 self.cache_new_heads_py_list(&head_revs, py);
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1679 self.cache_new_heads_node_ids_py_list(&head_revs, py);
51259
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1680
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1681 Ok(PyList::new(py, &res).into_object())
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1682 }
f20c4b307a5a rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51258
diff changeset
1683
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1684 fn inner_headrevs(
51966
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1685 &self,
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1686 py: Python,
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1687 filtered_revs: &PyObject,
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1688 stop_rev: &PyObject,
51966
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1689 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1690 let index = &self.inner(py).borrow().index;
51976
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1691 let stop_rev = if stop_rev.is_none(py) {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1692 None
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1693 } else {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1694 let rev = stop_rev.extract::<i32>(py)?;
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1695 if 0 <= rev && rev < index.len() as BaseRevision {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1696 Some(Revision(rev))
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1697 } else {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1698 None
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1699 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1700 };
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1701 let from_core = match (filtered_revs.is_none(py), stop_rev.is_none()) {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1702 (true, true) => index.head_revs_shortcut(),
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1703 (true, false) => {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1704 index.head_revs_advanced(&HashSet::new(), stop_rev, false)
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1705 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1706 _ => {
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1707 let filtered_revs =
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1708 rev_pyiter_collect(py, filtered_revs, index)?;
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1709 index.head_revs_advanced(
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1710 &filtered_revs,
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1711 stop_rev,
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1712 stop_rev.is_none(),
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1713 )
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1714 }
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1715 };
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1716
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1717 if stop_rev.is_some() {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1718 // we don't cache result for now
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1719 let new_heads = from_core
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1720 .map_err(|e| graph_error(py, e))?
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1721 .expect("this case should not be cached yet");
51966
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1722
51975
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1723 let as_vec: Vec<PyObject> = new_heads
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1724 .iter()
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1725 .map(|r| PyRevision::from(*r).into_py_object(py).into_object())
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1726 .collect();
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1727 Ok(PyList::new(py, &as_vec).into_object())
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1728 } else {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1729 if let Some(new_heads) =
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1730 from_core.map_err(|e| graph_error(py, e))?
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1731 {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1732 self.cache_new_heads_py_list(&new_heads, py);
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1733 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1734
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1735 Ok(self
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1736 .head_revs_py_list(py)
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1737 .borrow()
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1738 .as_ref()
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1739 .expect("head revs should be cached")
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1740 .clone_ref(py)
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1741 .into_object())
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1742 }
51966
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1743 }
e5dcaf6d4ac0 head-revs: move hg-cpython's inner_headrevsfiltered closer to inner_headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51964
diff changeset
1744
51394
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1745 fn check_revision(
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
1746 index: &Index,
51394
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1747 rev: UncheckedRevision,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1748 py: Python,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1749 ) -> PyResult<Revision> {
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1750 index
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1751 .check_revision(rev)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1752 .ok_or_else(|| rev_not_in_index(py, rev))
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1753 }
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1754
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1755 fn inner_headrevsdiff(
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1756 &self,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1757 py: Python,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1758 begin: &PyObject,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1759 end: &PyObject,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1760 ) -> PyResult<PyObject> {
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1761 let begin = begin.extract::<BaseRevision>(py)?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1762 let end = end.extract::<BaseRevision>(py)?;
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1763 let index = &self.inner(py).borrow().index;
51394
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1764 let begin =
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1765 Self::check_revision(index, UncheckedRevision(begin - 1), py)?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1766 let end = Self::check_revision(index, UncheckedRevision(end - 1), py)?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1767 let (removed, added) = index
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1768 .head_revs_diff(begin, end)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1769 .map_err(|e| graph_error(py, e))?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1770 let removed: Vec<_> =
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1771 removed.into_iter().map(PyRevision::from).collect();
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1772 let added: Vec<_> = added.into_iter().map(PyRevision::from).collect();
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1773 let res = (removed, added).to_py_object(py).into_object();
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1774 Ok(res)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1775 }
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1776
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1777 fn cache_new_heads_node_ids_py_list(
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1778 &self,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1779 new_heads: &[Revision],
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1780 py: Python<'_>,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1781 ) -> PyList {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1782 let index = &self.inner(py).borrow().index;
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1783 let as_vec: Vec<PyObject> = new_heads
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1784 .iter()
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1785 .map(|r| {
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1786 PyBytes::new(
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1787 py,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1788 index
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1789 .node(*r)
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1790 .expect("rev should have been in the index")
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1791 .as_bytes(),
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1792 )
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1793 .into_object()
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1794 })
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1795 .collect();
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1796 let new_heads_py_list = PyList::new(py, &as_vec);
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1797 *self.head_node_ids_py_list(py).borrow_mut() =
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1798 Some(new_heads_py_list.clone_ref(py));
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1799 new_heads_py_list
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1800 }
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1801
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1802 fn cache_new_heads_py_list(
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1803 &self,
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1804 new_heads: &[Revision],
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1805 py: Python<'_>,
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1806 ) -> PyList {
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1807 let as_vec: Vec<PyObject> = new_heads
51214
898674a4dbc7 rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51213
diff changeset
1808 .iter()
898674a4dbc7 rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51213
diff changeset
1809 .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: 51213
diff changeset
1810 .collect();
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1811 let new_heads_py_list = PyList::new(py, &as_vec);
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1812 *self.head_revs_py_list(py).borrow_mut() =
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1813 Some(new_heads_py_list.clone_ref(py));
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1814 new_heads_py_list
51213
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
1815 }
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1816
51222
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1817 fn inner_ancestors(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1818 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1819 py: Python,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1820 py_revs: &PyTuple,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1821 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1822 let index = &self.inner(py).borrow().index;
51222
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1823 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: 51219
diff changeset
1824 let as_vec: Vec<_> = index
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1825 .ancestors(&revs)
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1826 .map_err(|e| graph_error(py, e))?
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1827 .iter()
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1828 .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: 51219
diff changeset
1829 .collect();
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1830 Ok(PyList::new(py, &as_vec).into_object())
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1831 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1832
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1833 fn inner_commonancestorsheads(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1834 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1835 py: Python,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1836 py_revs: &PyTuple,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1837 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1838 let index = &self.inner(py).borrow().index;
51222
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1839 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: 51219
diff changeset
1840 let as_vec: Vec<_> = index
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1841 .common_ancestor_heads(&revs)
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1842 .map_err(|e| graph_error(py, e))?
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1843 .iter()
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1844 .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: 51219
diff changeset
1845 .collect();
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1846 Ok(PyList::new(py, &as_vec).into_object())
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1847 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1848
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1849 fn inner_computephasesmapsets(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1850 &self,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1851 py: Python,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1852 py_roots: PyDict,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1853 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1854 let index = &self.inner(py).borrow().index;
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1855 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: 51216
diff changeset
1856 .items_list(py)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1857 .iter(py)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1858 .map(|r| {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1859 let phase = r.get_item(py, 0)?;
51403
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51394
diff changeset
1860 let revs: Vec<_> =
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51394
diff changeset
1861 rev_pyiter_collect(py, &r.get_item(py, 1)?, index)?;
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1862 let phase = Phase::try_from(phase.extract::<usize>(py)?)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1863 .map_err(|_| revlog_error(py));
51403
f8bf1a8e9181 phases: keep internal state as rev-num instead of node-id
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51394
diff changeset
1864 Ok((phase?, revs))
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1865 })
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1866 .collect();
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1867 let (len, phase_maps) = index
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1868 .compute_phases_map_sets(roots?)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1869 .map_err(|e| graph_error(py, e))?;
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1870
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1871 // Ugly hack, but temporary
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1872 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: 51216
diff changeset
1873 let py_phase_maps = PyDict::new(py);
51423
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1874 for (idx, roots) in phase_maps.into_iter().enumerate() {
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1875 let phase_num = IDX_TO_PHASE_NUM[idx].into_py_object(py);
51423
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1876 // This is a bit faster than collecting into a `Vec` and passing
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1877 // it to `PySet::new`.
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1878 let set = PySet::empty(py)?;
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1879 for rev in roots {
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1880 set.add(py, PyRevision::from(rev).into_py_object(py))?;
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1881 }
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1882 py_phase_maps.set_item(py, phase_num, set)?;
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1883 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1884 Ok(PyTuple::new(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1885 py,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1886 &[
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1887 len.into_py_object(py).into_object(),
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1888 py_phase_maps.into_object(),
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1889 ],
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1890 )
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1891 .into_object())
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1892 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1893
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1894 fn inner_slicechunktodensity(
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1895 &self,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1896 py: Python,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1897 revs: PyObject,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1898 target_density: f64,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1899 min_gap_size: usize,
51216
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1900 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1901 let index = &self.inner(py).borrow().index;
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1902 let revs: Vec<_> = rev_pyiter_collect(py, &revs, index)?;
51216
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1903 let as_nested_vec =
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1904 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: 51215
diff changeset
1905 let mut res = Vec::with_capacity(as_nested_vec.len());
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1906 let mut py_chunk = Vec::new();
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1907 for chunk in as_nested_vec {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1908 py_chunk.clear();
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1909 py_chunk.reserve_exact(chunk.len());
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1910 for rev in chunk {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1911 py_chunk.push(
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1912 PyRevision::from(rev).into_py_object(py).into_object(),
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1913 );
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1914 }
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1915 res.push(PyList::new(py, &py_chunk).into_object());
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1916 }
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1917 // 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: 51215
diff changeset
1918 if res.len() == 1 {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1919 Ok(PyTuple::new(py, &res).into_object())
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1920 } else {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1921 Ok(PyList::new(py, &res).into_object())
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1922 }
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1923 }
51219
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1924
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1925 fn inner_reachableroots2(
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1926 &self,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1927 py: Python,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1928 min_root: UncheckedRevision,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1929 heads: PyObject,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1930 roots: PyObject,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1931 include_path: bool,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1932 ) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1933 let index = &self.inner(py).borrow().index;
51219
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1934 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: 51217
diff changeset
1935 PyErr::new::<IndexError, _>(py, "head out of range")
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1936 })?;
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1937 let roots: Result<_, _> = roots
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1938 .iter(py)?
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1939 .map(|r| {
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1940 r.and_then(|o| match o.extract::<PyRevision>(py) {
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1941 Ok(r) => Ok(UncheckedRevision(r.0)),
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1942 Err(e) => Err(e),
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1943 })
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1944 })
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1945 .collect();
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1946 let as_set = index
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1947 .reachable_roots(min_root, heads, roots?, include_path)
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1948 .map_err(|e| graph_error(py, e))?;
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1949 let as_vec: Vec<PyObject> = as_set
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1950 .iter()
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1951 .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: 51217
diff changeset
1952 .collect();
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1953 Ok(PyList::new(py, &as_vec).into_object())
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1954 }
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1955 fn inner_issnapshot(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1956 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1957 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1958 rev: UncheckedRevision,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1959 ) -> PyResult<bool> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1960 let inner = &self.inner(py).borrow();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1961 let index = &self.inner(py).borrow().index;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1962 let rev = index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1963 .check_revision(rev)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1964 .ok_or_else(|| rev_not_in_index(py, rev))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1965 let result = inner.is_snapshot(rev).map_err(|e| {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1966 PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1967 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1968 Ok(result)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1969 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1970 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1971
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1972 impl InnerRevlog {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1973 pub fn inner_new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1974 py: Python,
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
1975 vfs_base: PyObject,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
1976 fncache: PyObject,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
1977 vfs_is_readonly: bool,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1978 index_data: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1979 index_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1980 data_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1981 _sidedata_file: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1982 inline: bool,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1983 data_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1984 delta_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1985 feature_config: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1986 _chunk_cache: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1987 _default_compression_header: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1988 revlog_type: usize,
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
1989 use_persistent_nodemap: bool,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1990 ) -> PyResult<Self> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1991 let index_file =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1992 get_path_from_bytes(index_file.extract::<PyBytes>(py)?.data(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1993 .to_owned();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1994 let data_file =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1995 get_path_from_bytes(data_file.extract::<PyBytes>(py)?.data(py))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1996 .to_owned();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1997 let revlog_type = RevlogType::try_from(revlog_type)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1998 .map_err(|e| revlog_error_from_msg(py, e))?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1999 let data_config = extract_data_config(py, data_config, revlog_type)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2000 let delta_config =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2001 extract_delta_config(py, delta_config, revlog_type)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2002 let feature_config =
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2003 extract_feature_config(py, feature_config, revlog_type)?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2004 let options = RevlogOpenOptions::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2005 inline,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2006 data_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2007 delta_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2008 feature_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2009 );
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2010
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2011 // Safety: we keep the buffer around inside the class as `index_mmap`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2012 let (buf, bytes) = unsafe { mmap_keeparound(py, index_data)? };
52178
bd8081e9fd62 rust: don't star export from the `revlog` module
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52176
diff changeset
2013 let index = Index::new(bytes, options.index_header())
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2014 .map_err(|e| revlog_error_from_msg(py, e))?;
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2015
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2016 let base = &vfs_base.extract::<PyBytes>(py)?;
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2017 let base = get_path_from_bytes(base.data(py)).to_owned();
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2018 let core = CoreInnerRevlog::new(
52172
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2019 Box::new(FnCacheVfs::new(
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2020 base,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2021 vfs_is_readonly,
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2022 Box::new(PyFnCache::new(fncache)),
72bc29f01570 revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52163
diff changeset
2023 )),
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2024 index,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2025 index_file,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2026 data_file,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2027 data_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2028 delta_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2029 feature_config,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2030 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2031 Self::create_instance(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2032 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2033 core,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2034 RefCell::new(None),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2035 RefCell::new(None),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2036 RefCell::new(None),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2037 RefCell::new(buf),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2038 RefCell::new(None),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2039 RefCell::new(None),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2040 RefCell::new(None),
52174
bcd4962e0df9 rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52172
diff changeset
2041 use_persistent_nodemap,
52176
1032bb0ef365 rust-revlog: build an in-memory nodemap if a given revlog gets queried a lot
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52175
diff changeset
2042 AtomicUsize::new(0),
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2043 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2044 }
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2045 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2046
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2047 py_class!(pub class NodeTree |py| {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2048 data nt: RefCell<CoreNodeTree>;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2049 data index: RefCell<UnsafePyLeaked<PySharedIndex>>;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2050
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2051 def __new__(_cls, index: PyObject) -> PyResult<NodeTree> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2052 let index = py_rust_index_to_graph(py, index)?;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2053 let nt = CoreNodeTree::default(); // in-RAM, fully mutable
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2054 Self::create_instance(py, RefCell::new(nt), RefCell::new(index))
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2055 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2056
51248
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2057 /// Tell whether the NodeTree is still valid
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2058 ///
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2059 /// In case of mutation of the index, the given results are not
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2060 /// guaranteed to be correct, and in fact, the methods borrowing
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2061 /// the inner index would fail because of `PySharedRef` poisoning
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2062 /// (generation-based guard), same as iterating on a `dict` that has
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2063 /// been meanwhile mutated.
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2064 def is_invalidated(&self) -> PyResult<bool> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2065 let leaked = &self.index(py).borrow();
51252
24d3298189d7 rust-index: document safety invariants being upheld for every `unsafe` block
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51251
diff changeset
2066 // Safety: we don't leak the "faked" reference out of `UnsafePyLeaked`
51248
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2067 let result = unsafe { leaked.try_borrow(py) };
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2068 // two cases for result to be an error:
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2069 // - the index has previously been mutably borrowed
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2070 // - there is currently a mutable borrow
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2071 // in both cases this amounts for previous results related to
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2072 // the index to still be valid.
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2073 Ok(result.is_err())
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2074 }
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
2075
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2076 def insert(&self, rev: PyRevision) -> PyResult<PyObject> {
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2077 let leaked = &self.index(py).borrow();
51252
24d3298189d7 rust-index: document safety invariants being upheld for every `unsafe` block
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51251
diff changeset
2078 // Safety: we don't leak the "faked" reference out of `UnsafePyLeaked`
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2079 let index = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2080
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2081 let rev = UncheckedRevision(rev.0);
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2082 let rev = index
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2083 .check_revision(rev)
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2084 .ok_or_else(|| rev_not_in_index(py, rev))?;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2085 if rev == NULL_REVISION {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2086 return Err(rev_not_in_index(py, rev.into()))
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2087 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2088
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2089 let entry = index.inner.get_entry(rev).expect("entry should exist");
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2090 let mut nt = self.nt(py).borrow_mut();
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2091 nt.insert(index, entry.hash(), rev).map_err(|e| nodemap_error(py, e))?;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2092
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2093 Ok(py.None())
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2094 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2095
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2096 /// Lookup by node hex prefix in the NodeTree, returning revision number.
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2097 ///
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2098 /// This is not part of the classical NodeTree API, but is good enough
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2099 /// for unit testing, as in `test-rust-revlog.py`.
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2100 def prefix_rev_lookup(
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2101 &self,
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2102 node_prefix: PyBytes
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2103 ) -> PyResult<Option<PyRevision>> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2104 let prefix = NodePrefix::from_hex(node_prefix.data(py))
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2105 .map_err(|_| PyErr::new::<ValueError, _>(
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2106 py,
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2107 format!("Invalid node or prefix {:?}",
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2108 node_prefix.as_object()))
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2109 )?;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2110
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2111 let nt = self.nt(py).borrow();
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2112 let leaked = &self.index(py).borrow();
51252
24d3298189d7 rust-index: document safety invariants being upheld for every `unsafe` block
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51251
diff changeset
2113 // Safety: we don't leak the "faked" reference out of `UnsafePyLeaked`
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2114 let index = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2115
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2116 Ok(nt.find_bin(index, prefix)
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2117 .map_err(|e| nodemap_error(py, e))?
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2118 .map(|r| r.into())
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2119 )
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2120 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2121
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2122 def shortest(&self, node: PyBytes) -> PyResult<usize> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2123 let nt = self.nt(py).borrow();
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2124 let leaked = &self.index(py).borrow();
51252
24d3298189d7 rust-index: document safety invariants being upheld for every `unsafe` block
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51251
diff changeset
2125 // Safety: we don't leak the "faked" reference out of `UnsafePyLeaked`
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2126 let idx = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2127 match nt.unique_prefix_len_node(idx, &node_from_py_bytes(py, &node)?)
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2128 {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2129 Ok(Some(l)) => Ok(l),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2130 Ok(None) => Err(revlog_error(py)),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2131 Err(e) => Err(nodemap_error(py, e)),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2132 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2133 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2134 });
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2135
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2136 fn panic_after_error(_py: Python) -> ! {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2137 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2138 python3_sys::PyErr_Print();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2139 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2140 panic!("Python API called failed");
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2141 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2142
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2143 /// # Safety
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2144 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2145 /// Don't call this. Its only caller is taken from `PyO3`.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2146 unsafe fn cast_from_owned_ptr_or_panic<T>(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2147 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2148 p: *mut python3_sys::PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2149 ) -> T
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2150 where
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2151 T: cpython::PythonObjectWithCheckedDowncast,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2152 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2153 if p.is_null() {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2154 panic_after_error(py);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2155 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2156 PyObject::from_owned_ptr(py, p).cast_into(py).unwrap()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2157 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2158 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2159
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2160 fn with_pybytes_buffer<F>(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2161 py: Python,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2162 len: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2163 init: F,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2164 ) -> Result<PyBytes, RevlogError>
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2165 where
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2166 F: FnOnce(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2167 &mut dyn RevisionBuffer<Target = PyBytes>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2168 ) -> Result<(), RevlogError>,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2169 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2170 // Largely inspired by code in PyO3
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2171 // https://pyo3.rs/main/doc/pyo3/types/struct.pybytes#method.new_bound_with
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2172 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2173 let pyptr = python3_sys::PyBytes_FromStringAndSize(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2174 std::ptr::null(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2175 len as python3_sys::Py_ssize_t,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2176 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2177 let pybytes = cast_from_owned_ptr_or_panic::<PyBytes>(py, pyptr);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2178 let buffer: *mut u8 = python3_sys::PyBytes_AsString(pyptr).cast();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2179 debug_assert!(!buffer.is_null());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2180 let mut rev_buf = PyRevisionBuffer::new(pybytes, buffer, len);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2181 // Initialise the bytestring in init
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2182 // If init returns an Err, the buffer is deallocated by `pybytes`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2183 init(&mut rev_buf).map(|_| rev_buf.finish())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2184 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2185 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2186
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2187 /// Wrapper around a Python-provided buffer into which the revision contents
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2188 /// will be written. Done for speed in order to save a large allocation + copy.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2189 struct PyRevisionBuffer {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2190 py_bytes: PyBytes,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2191 _buf: *mut u8,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2192 len: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2193 current_buf: *mut u8,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2194 current_len: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2195 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2196
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2197 impl PyRevisionBuffer {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2198 /// # Safety
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2199 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2200 /// `buf` should be the start of the allocated bytes of `bytes`, and `len`
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2201 /// exactly the length of said allocated bytes.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2202 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2203 unsafe fn new(bytes: PyBytes, buf: *mut u8, len: usize) -> Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2204 Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2205 py_bytes: bytes,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2206 _buf: buf,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2207 len,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2208 current_len: 0,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2209 current_buf: buf,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2210 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2211 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2212
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2213 /// Number of bytes that have been copied to. Will be different to the
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2214 /// total allocated length of the buffer unless the revision is done being
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2215 /// written.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2216 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2217 fn current_len(&self) -> usize {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2218 self.current_len
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2219 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2220 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2221
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2222 impl RevisionBuffer for PyRevisionBuffer {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2223 type Target = PyBytes;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2224
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2225 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2226 fn extend_from_slice(&mut self, slice: &[u8]) {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2227 assert!(self.current_len + slice.len() <= self.len);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2228 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2229 // We cannot use `copy_from_nonoverlapping` since it's *possible*
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2230 // to create a slice from the same Python memory region using
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2231 // [`PyBytesDeref`]. Probable that LLVM has an optimization anyway?
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2232 self.current_buf.copy_from(slice.as_ptr(), slice.len());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2233 self.current_buf = self.current_buf.add(slice.len());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2234 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2235 self.current_len += slice.len()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2236 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2237
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2238 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2239 fn finish(self) -> Self::Target {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2240 // catch unzeroed bytes before it becomes undefined behavior
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2241 assert_eq!(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2242 self.current_len(),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2243 self.len,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2244 "not enough bytes read for revision"
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2245 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2246 self.py_bytes
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2247 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2248 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2249
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2250 fn revlog_error(py: Python) -> PyErr {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2251 match py
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2252 .import("mercurial.error")
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2253 .and_then(|m| m.get(py, "RevlogError"))
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2254 {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2255 Err(e) => e,
47305
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2256 Ok(cls) => PyErr::from_instance(
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2257 py,
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2258 cls.call(py, (py.None(),), None).ok().into_py_object(py),
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2259 ),
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2260 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2261 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2262
51212
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2263 fn graph_error(py: Python, _err: hg::GraphError) -> PyErr {
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2264 // ParentOutOfRange is currently the only alternative
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2265 // in `hg::GraphError`. The C index always raises this simple ValueError.
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2266 PyErr::new::<ValueError, _>(py, "parent out of range")
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2267 }
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2268
51196
44fbb7dfb563 rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents: 51195
diff changeset
2269 fn nodemap_rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr {
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2270 PyErr::new::<ValueError, _>(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2271 py,
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2272 format!(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2273 "Inconsistency: Revision {} found in nodemap \
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2274 is not in revlog index",
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2275 rev
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2276 ),
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2277 )
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2278 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2279
51197
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2280 fn rev_not_in_index(py: Python, rev: UncheckedRevision) -> PyErr {
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2281 PyErr::new::<ValueError, _>(
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2282 py,
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2283 format!("revlog index out of range: {}", rev),
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2284 )
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2285 }
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2286
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2287 /// Standard treatment of NodeMapError
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2288 fn nodemap_error(py: Python, err: NodeMapError) -> PyErr {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2289 match err {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2290 NodeMapError::MultipleResults => revlog_error(py),
51196
44fbb7dfb563 rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents: 51195
diff changeset
2291 NodeMapError::RevisionNotInIndex(r) => nodemap_rev_not_in_index(py, r),
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2292 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2293 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2294
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2295 /// Create the module, with __package__ given from parent
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2296 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2297 let dotted_name = &format!("{}.revlog", package);
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2298 let m = PyModule::new(py, dotted_name)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2299 m.add(py, "__package__", package)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2300 m.add(py, "__doc__", "RevLog - Rust implementations")?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2301
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2302 m.add_class::<NodeTree>(py)?;
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2303 m.add_class::<InnerRevlog>(py)?;
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2304
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2305 let sys = PyModule::import(py, "sys")?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2306 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2307 sys_modules.set_item(py, dotted_name, &m)?;
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2308
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2309 Ok(m)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2310 }