annotate rust/hg-cpython/src/revlog.rs @ 52163:7346f93be7a4

revlog: add the glue to use the Rust `InnerRevlog` from Python The performance of this has been looked at for quite some time, and some workflows are actually quite a bit faster than with the Python + C code. However, we are still (up to 20%) slower in some crucial places like cloning certain repos, log, cat, which makes this an incomplete rewrite. This is mostly due to the high amount of overhead in Python <-> Rust FFI, especially around the VFS code. A future patch series will rewrite the VFS code in pure Rust, which should hopefully get us up to par with current perfomance, if not better in all important cases. This is a "save state" of sorts, as this is a ton of code, and I don't want to pile up even more things in a single review. Continuing to try to match the current performance will take an extremely long time, if it's not impossible, without the aforementioned VFS work.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 19 Jun 2024 19:10:49 +0200
parents f2eab4967bfc
children 72bc29f01570
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},
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
13 vfs::PyVfs,
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
14 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
15 };
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
16 use cpython::{
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
17 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
18 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
19 ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, 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
20 PyModule, PyObject, PyResult, PySet, 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
21 PythonObject, ToPyObject, UnsafePyLeaked,
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
22 };
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
23 use hg::{
51209
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
24 errors::HgError,
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
25 index::{Phase, RevisionDataParams, SnapshotsCache, INDEX_ENTRY_SIZE},
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
26 nodemap::{Block, NodeMapError, NodeTree as CoreNodeTree},
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
27 revlog::compression::CompressionConfig,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
28 revlog::inner_revlog::InnerRevlog as CoreInnerRevlog,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
29 revlog::inner_revlog::RevisionBuffer,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
30 revlog::options::{
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
31 RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
32 RevlogOpenOptions,
51226
1b23aaf5eb7b rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents: 51222
diff changeset
33 },
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
34 revlog::{nodemap::NodeMap, Graph, NodePrefix, RevlogError, RevlogIndex},
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
35 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
36 utils::files::{get_bytes_from_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
37 BaseRevision, Node, Revision, RevlogType, UncheckedRevision,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
38 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
39 };
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
40 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
41 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
42 collections::{HashMap, HashSet},
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
43 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
44 };
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
45 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
46
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
47 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
48 /// The underlying hg-core index
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
49 pub(crate) inner: &'static hg::index::Index,
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 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
51
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 /// 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
53 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
54 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
55 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
56 ) -> 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
57 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
58 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
59 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
60 // 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
61 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
62 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
63
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
64 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
65 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
66 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
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
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 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
71 #[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
72 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
73 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
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 }
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 51232
diff changeset
76
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 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
78 #[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
79 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
80 &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
81 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
82 ) -> 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
83 {
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 // 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
85 // 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
86 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
87 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
88 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
89 }
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 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
91 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
92 }
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 }
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 }
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
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 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
98 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
99 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
100 }
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 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
102 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
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
51184
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
106 /// 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
107 /// 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
108 /// 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
109 /// 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
110 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
111 /// # Safety
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
112 ///
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
113 /// 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
114 /// 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
115 #[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
116 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
117 py: Python,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
118 data: PyObject,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
119 ) -> PyResult<(
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
120 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
121 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
122 )> {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
123 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
124 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
125
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
126 // 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
127 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
128 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
129 && 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
130 && 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
131 {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
132 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
133 } else {
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
134 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
135 py,
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
136 "Nodemap data buffer has an invalid memory representation"
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
137 .to_string(),
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
138 ));
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
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
141 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
142 }
8c4e8d06432e rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51183
diff changeset
143
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
144 fn py_tuple_to_revision_data_params(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
145 py: Python,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
146 tuple: PyTuple,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
147 ) -> PyResult<RevisionDataParams> {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
148 if tuple.len(py) < 8 {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
149 // 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
150 return Err(PyErr::new::<IndexError, _>(
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
151 py,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
152 "tuple index out of range",
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
153 ));
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
154 }
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
155 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
156 let node_id = tuple
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
157 .get_item(py, 7)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
158 .extract::<PyBytes>(py)?
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
159 .data(py)
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
160 .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
161 .expect("nodeid should be set");
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
162 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
163 let data_offset = offset_or_flags >> 16;
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
164 Ok(RevisionDataParams {
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
165 flags,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
166 data_offset,
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
167 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
168 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
169 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
170 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
171 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
172 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
173 node_id,
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
174 ..Default::default()
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
175 })
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
176 }
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
177 fn revision_data_params_to_py_tuple(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
178 py: Python,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
179 params: RevisionDataParams,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
180 ) -> PyTuple {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
181 PyTuple::new(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
182 py,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
183 &[
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
184 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
185 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
186 .data_compressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
187 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
188 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
189 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
190 .data_uncompressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
191 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
192 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
193 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
194 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
195 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
196 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
197 PyBytes::new(py, &params.node_id)
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._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
201 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
202 ._sidedata_compressed_length
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
203 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
204 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
205 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
206 .data_compression_mode
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
207 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
208 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
209 params
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
210 ._sidedata_compression_mode
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
211 .into_py_object(py)
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
212 .into_object(),
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
213 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
214 ],
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
215 )
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
216 }
51189
65c9032e2e5a rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51188
diff changeset
217
51209
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
218 struct PySnapshotsCache<'p> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
219 py: Python<'p>,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
220 dict: PyDict,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
221 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
222
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
223 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
224 fn insert_for(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
225 &mut self,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
226 rev: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
227 value: BaseRevision,
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
228 ) -> Result<(), RevlogError> {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
229 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
230 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
231 Some(obj) => obj
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
232 .extract::<PySet>(self.py)
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
233 .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
234 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
235 .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
236 }
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
237 .map_err(|_| {
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
238 RevlogError::Other(HgError::unsupported(
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
239 "Error in Python caches handling",
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
240 ))
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
241 })
9b06e7f32bc5 rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51208
diff changeset
242 }
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
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
245 // 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
246 // 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
247 // 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
248 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
249 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
250 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
251 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
252 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
253 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
254
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
255 /// 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
256 /// 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
257 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
258 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
259 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
260 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
261 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
262 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
263 ) -> 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
264 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
265 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
266 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
267 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
268 // 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
269 // 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
270 // 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
271 // 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
272 // 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
273 // 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
274 // 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
275 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
276 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
277 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
278 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
279 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
280 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
281 // 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
282 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
283 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
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 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
288 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
289 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
290 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
291 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
292 ) -> 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
293 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
294 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
295 .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
296 .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
297
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
298 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
299 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
300 .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
301 .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
302 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
303 .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
304 .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
305 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
306 .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
307 .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
308 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
309 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
310 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
311 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
312 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
313 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
314 .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
315 .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
316 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
317 .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
318 .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
319 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
320 .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
321 .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
322 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
323 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
324 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
325 .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
326 .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
327 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
328 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
329 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
330 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
331 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
332 &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
333 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
334 &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
335 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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
338
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
339 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
340 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
341 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
342 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
343 ) -> 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
344 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
345 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
346 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
347 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
348 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
349 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
350 .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
351 .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
352 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
353 .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
354 .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 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
356 .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
357 .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
358 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
359 .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
360 .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
361 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
362 .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
363 .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
364 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
365 .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
366 .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
367 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
368 .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
369 .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
370 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
371 .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
372 .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
373 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
374 .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
375 .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
376 })
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
377 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
378
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
379 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
380 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
381 &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
382 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
383 &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
384 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
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 }
51187
6ec8387eb0be rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51184
diff changeset
387
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
388 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
389 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
390 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
391 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
392 ) -> 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
393 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
394 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
395 .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
396 .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
397 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
398 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
399 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
400 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
401 .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
402 .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
403 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
404 .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
405 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
406 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
407 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
408 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
409 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
410 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
411 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
412 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
413 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
414 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
415 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
416 engine
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
417 .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
418 .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
419 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
420 engine
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
421 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
422 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
423 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
424 .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
425 .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
426 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
427 .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
428 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
429 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
430 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
431 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
432 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
433 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
434 } else {
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 = 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
436 .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
437 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
438 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
439 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
440 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
441 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
442 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
443 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
444 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
445 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
446 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
447 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
448 .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
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 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
451 e => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
452 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
453 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
454 format!(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
455 "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
456 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
457 ),
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
458 ))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
459 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
460 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
461 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
462 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 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
464 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
465 .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
466 .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
467 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
468 .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
469 .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
470 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
471 .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
472 .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
473 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
474 .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
475 .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
476 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
477 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
478 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
479 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
480 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
481 &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
482 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
483 &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
484 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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
487
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
488 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
489 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
490
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
491 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
492 .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
493 .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
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 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
496 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
497 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
498 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
499 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
500 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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
503 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
504 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
505
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_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
507 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
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 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
510 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
511 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
512 .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
513 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
514 .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
515 .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
516 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
517 // `__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
518 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
519 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
520 .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
521 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
522 .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
523 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
524 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
525 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
526 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
527
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
528 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
529 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
530 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
531 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
532 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
533 ) -> 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
534 // 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
535 // 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
536 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
537 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
538 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
539
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
540 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
541 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
542 .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
543 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
544 .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
545 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
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 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
548
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
549 // 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
550 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
551 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
552
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
553 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
554 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
555 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
556 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
557 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
558
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
559 // 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
560 // 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
561 // (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
562 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
563
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
564 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
565 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
566 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
567 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
568 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
569
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
570 /// 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
571 /// 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
572 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
573 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
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 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
577 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
578 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
579 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
580 }
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 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
583 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
584 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
585 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
586 Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
587 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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
590 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
591
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
592 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
593 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
594 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
595 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
596 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
597 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
598 .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
599 .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
600 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
601 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
602
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
603 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
604 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
605 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
606 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
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 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
609 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
610 .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
611 .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
612 .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
613 .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
614 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
615 &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
616 ).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
617 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
618 // `__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
619 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
620 .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
621 .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
622 .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 .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
624 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
625 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
626 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
627 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
628
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
629 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
630 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
631 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
632 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
633 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
634 ) -> 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
635 // 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
636 // 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
637 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
638 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
639 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
640
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
641 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
642 .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
643 .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
644 .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
645 .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
646 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
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 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
649
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
650 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
651 @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
652 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
653 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
654 // 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
655 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
656 // 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
657 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
658 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
659 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
660 data revision_cache: 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
661
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
662 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
663 _cls,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
664 opener: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
665 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
666 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
667 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
668 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
669 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
670 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
671 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
672 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
673 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
674 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
675 revlog_type: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
676 ) -> 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
677 Self::inner_new(
44503
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
678 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
679 opener,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
680 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
681 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
682 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
683 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
684 inline,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
685 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
686 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
687 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
688 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
689 default_compression_header,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
690 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
691 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
692 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
693
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
694 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
695 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
696 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
697 self.inner(py).borrow_mut().clear_cache();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
698 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
699 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
700
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
701 @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
702 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
703 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
704 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
705
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
706 @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
707 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
708 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
709
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
710 @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
711 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
712 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
713 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
714 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
715 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
716 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
717 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
718
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
719 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
720
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
721 @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
722 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
723
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
724 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
725 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
726
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
727 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
728 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
729 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
730 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
731 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
732 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
733 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
734 None
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
735 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
736 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
737 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
738 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
739 (
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
740 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
741 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
742 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
743
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
744 ).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
745 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
746 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
747 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
748
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
749 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
750
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
751 @_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
752 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
753 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
754 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
755 *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
756 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
757 None => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
758 // 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
759 // 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
760 // 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
761 self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
762 .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
763 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
764 .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
765 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
766 .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
767 .take();
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 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
770 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
771 self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
772 .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
773 .borrow()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
774 .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
775 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
776 .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
777 .take();
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
778 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
779 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
780 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
781 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
782 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
783 // 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
784 // checked
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
785 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
786 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
787 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
788 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
789 .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
790 .lock()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
791 .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
792 *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
793 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
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 Ok(())
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
799 @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
800 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
801 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
802
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
803 @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
804 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
805 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
806 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
807 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
808 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
809 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
810 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
811 }
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 @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
814 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
815 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
816 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
817 &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
818 )
44503
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
819 )
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
820 }
887d0f921b34 rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents: 44070
diff changeset
821
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
822 @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
823 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
824 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
825 ) -> PyResult<()> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
826 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
827 value
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
828 .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
829 .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
830 .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
831 ).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
832 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
833 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
834 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
835
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 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
837 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
838 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
839
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
840 @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
841 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
842 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
843
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
844 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
845 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
846 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
847
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
848 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
849 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
850 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
851 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
852 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
853 &[
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
854 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
855 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
856 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
857 ]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
858 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
859 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
860 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
861
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
862 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
863 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
864 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
865 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
866 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
867 .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
868 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
869 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
870 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
871 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
872 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
873 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
874 Ok(
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 header,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
877 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
878 ).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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
881
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
882 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
883 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
884 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
885 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
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 }
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 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
890 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
891 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
892 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
893 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
894 ) -> 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
895 // 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
896 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
897 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
898 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
899 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
900 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
901 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
902 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
903 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
904
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
905 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
906 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
907 _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
908 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
909 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
910 ) -> 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
911 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
912 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
913 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
914 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
915 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
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 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
918 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
919 let header = hg::index::IndexHeader::parse(&header.to_be_bytes());
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
920 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
921 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
922 .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
923 .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
924 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
925 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
926
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
927 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
928 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
929 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
930 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
931 ) -> 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
932 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
933 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
934 .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
935 .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
936 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
937 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
940 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
941 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
942 _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
943 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
944 ) -> 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
945 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
946 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
947 inner
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
948 .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
949 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
950 Ok(())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
951 }).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
952 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
953 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
954
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
955 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
956 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
957 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
958 ) -> 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
959 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
960 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
961 .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
962 .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
963 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
964 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
967 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
968 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
969 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
970 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
971 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
972 _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
973 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
974 _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
975 _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
976 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
977 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
978 _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
979 ) -> 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
980 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
981 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
982 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
983 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
984 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
985 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
986 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
987 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
988 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
989 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
990 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
991 transaction,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
992 &entry,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
993 (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
994 offset,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
995 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
996 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
997 ).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
998 .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
999 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1000 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1001
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1002 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
1003 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
1004 .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
1005 .delay()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1006 .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
1007 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
1008 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1009
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1010 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
1011 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
1012 .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
1013 .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
1014 .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
1015 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
1016 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
1017 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
1018 },
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1019 None => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1020 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
1021 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1022 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1023 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1024 (
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1025 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
1026 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
1027 ).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
1028 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1029 }
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 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
1032 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
1033 .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
1034 .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
1035 .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
1036 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
1037 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1038
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1039 // -- 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
1040
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1041 def _index_get_rev(&self, node: PyBytes) -> PyResult<Option<PyRevision>> {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1042 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
1043 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1050
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1051 /// 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
1052 /// 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
1053 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1054 /// 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
1055 /// 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
1056 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
1057 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
1058 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1059
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1060 /// 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
1061 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
1062 // 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
1063 // 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
1064 // 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
1065 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
1066 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1067
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1068 /// 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
1069 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
1070 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
1071 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
1072 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
1073 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
1074 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1075 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
1076 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
1077 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
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 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1080
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1081 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
1082 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1083 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
1084 ) -> 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
1085 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
1086 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
1087 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
1088
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1089 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
1090 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
1091
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 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
1093 .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
1094 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1097 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
1098 // 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
1099 .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
1100 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
1101 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1102 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
1103 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1104 }))
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1105 .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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1109 /// 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
1110 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
1111 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
1112 // 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
1113 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
1114 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
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 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
1117 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
1118
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1119 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
1120
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1121 // 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
1122 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
1123 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
1124 .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
1125 .index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1126 .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
1127 .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
1128 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
1129 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
1130 .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
1131 .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
1132 .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
1133 .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
1134 .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
1135 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
1136 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1137
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1138 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
1139 // __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
1140 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
1141 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
1142 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1143 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
1144 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
1145 };
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1146 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
1147 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
1148 .index
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1149 .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
1150 .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
1151 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
1152 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1153 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
1154 .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
1155 .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
1156 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
1157 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
1158 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
1159 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
1160 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
1161 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
1162 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1164 /// 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
1165 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
1166 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
1167 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
1168 }
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 /// 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
1171 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
1172 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1173 *args,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1174 **_kw
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<PyObject> {
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 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
1177 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
1178 }
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 /// 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
1181 /// 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
1182 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
1183 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
1184 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
1185 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
1186 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
1187 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
1188 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
1189 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
1190 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1191
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1192 /// 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
1193 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
1194 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
1195 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
1196 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
1197 |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
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 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
1200 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
1201 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1202
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1203
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 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
1205 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
1206 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
1207 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
1208 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
1209 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
1210 }
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 /// 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
1213 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
1214 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1215 *args,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1216 **_kw
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1217 ) -> 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
1218 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
1219 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
1220 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
1221 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1222
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1223 /// reachableroots
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1224 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
1225 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
1226 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1227 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
1228 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
1229 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
1230 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
1231 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1232 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
1233 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1234
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1235 /// 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241 _ => 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
1242 }?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1243 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
1244 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1245
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1246 /// 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
1247 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
1248 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
1249 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
1250 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1251
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1252 /// 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
1253 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
1254 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
1255 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1256 &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
1257 &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
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 /// 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
1262 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
1263 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
1264 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
1265 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1266
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1267 /// 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
1268 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
1269 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
1270 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
1271 // 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
1272 // 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
1273 // 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
1274 // caches.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1275 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
1276 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
1277 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
1278 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1279
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1280 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
1281 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
1282 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
1283 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
1284 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
1285 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
1286 &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
1287 ).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
1288 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1291 /// 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
1292 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
1293 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
1294 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
1295 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
1296 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
1297 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
1298 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
1299 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1300 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
1301 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
1302 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
1303 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
1304 })?)
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1305 } 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
1306 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
1307 .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
1308 .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
1309 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
1310 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
1311 ).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
1312 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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1315 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
1316 Ok(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1317 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
1318 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 &[
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1320 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
1321 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
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 ).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
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
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1327 /// 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
1328 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
1329 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
1330 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1331 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
1332 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
1333 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
1334 )?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1335 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
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
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___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
1339 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
1340 }
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 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
1343 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
1344 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
1345 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1346
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1347 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
1348 // 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
1349 // 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
1350 // 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
1351 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
1352 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
1353 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
1354 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1355 Err(_) => {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1356 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
1357 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
1358 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
1359 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1360 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1361 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1362
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1363 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
1364 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
1365 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1366
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1367 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
1368 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
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 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
1372 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1373 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
1374 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
1375 ) -> 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
1376 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
1377 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1378
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1379 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1380 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
1381 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
1382 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
1383 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1384
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1385 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1386 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
1387 // 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
1388 // 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
1389 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
1390 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
1391 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1392
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1393 @property
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1394 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
1395 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
1396 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1397
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1398
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1399 });
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1400
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1401 /// 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
1402 impl InnerRevlog {
51190
e79b0a4be3a7 rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51189
diff changeset
1403 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
1404 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
1405 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
1406 }
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
1407 /// 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
1408 /// 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
1409 /// 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
1410 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
1411 &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
1412 py: Python,
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1413 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
1414 ) -> 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
1415 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
1416 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
1417 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
1418 // 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
1419 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
1420 .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
1421 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1422 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
1423 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1424
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1425 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
1426 &'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
1427 py: Python<'a>,
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1428 ) -> 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
1429 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
1430 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
1431 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
1432 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
1433 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
1434 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1435 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
1436 }
857cc79247ac rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents: 44506
diff changeset
1437
44508
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1438 /// 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
1439 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
1440 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
1441 .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
1442 .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
1443 .take()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1444 .expect("nodetree should exist");
44508
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1445 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
1446
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1447 // 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
1448 // scratch
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1449 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
1450 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
1451 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
1452
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1453 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
1454 assert_eq!(readonly.len(), 0);
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1455
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1456 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1457 } else {
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1458 bytes
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1459 };
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1460
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1461 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
1462 Ok(bytes)
b581231ae9d1 rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents: 44507
diff changeset
1463 }
44509
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1464
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1465 /// 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
1466 /// (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
1467 fn inner_nodemap_data_incremental(
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1468 &self,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1469 py: Python,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1470 ) -> PyResult<PyObject> {
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1471 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
1472 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
1473 Some(d) => d,
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1474 None => return Ok(py.None()),
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1475 };
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1476
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1477 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
1478 .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
1479 .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
1480 .take()
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1481 .expect("nodetree should exist");
44509
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1482 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
1483 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
1484 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
1485
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1486 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
1487 .to_py_object(py)
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1488 .into_object())
5bbf887275b0 rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents: 44508
diff changeset
1489 }
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1490
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1491 /// 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
1492 /// 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
1493 fn inner_update_nodemap_data(
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1494 &self,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1495 py: Python,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1496 docket: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1497 nm_data: PyObject,
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1498 ) -> 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
1499 // 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
1500 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
1501 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
1502 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
1503
51244
8dbd985733ff rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents: 51243
diff changeset
1504 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
1505
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1506 let data_tip = docket
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1507 .getattr(py, "tip_rev")?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1508 .extract::<BaseRevision>(py)?
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1509 .into();
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1510 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
1511 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
1512 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
1513 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
1514 })?;
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1515 let current_tip = idx.len();
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1516
50976
4c5f6e95df84 rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents: 50974
diff changeset
1517 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
1518 let rev = Revision(r);
44510
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1519 // 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
1520 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
1521 .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
1522 }
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1523
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1524 *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
1525
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1526 Ok(py.None())
15febf99a9c6 rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents: 44509
diff changeset
1527 }
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1528
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1529 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
1530 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
1531 Ok(match key.extract::<BaseRevision>(py) {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1532 Ok(key_as_int) => {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1533 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
1534 RevisionDataParams::default()
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1535 } else {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1536 let rev = UncheckedRevision(key_as_int);
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1537 match idx.entry_as_params(rev) {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1538 Some(e) => e,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1539 None => {
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1540 return Err(PyErr::new::<IndexError, _>(
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1541 py,
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1542 "revlog index out of range",
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1543 ));
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1544 }
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1545 }
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1546 };
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1547 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
1548 .into_object()
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1549 }
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1550 _ => self
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1551 ._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
1552 .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
1553 || 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
1554 |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
1555 ),
51202
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1556 })
002b49905aac rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51201
diff changeset
1557 }
51212
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
1558
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
1559 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
1560 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
1561
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
1562 // 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
1563 // 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
1564 // 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
1565 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
1566 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
1567 .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
1568 .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
1569 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
1570 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
1571 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
1572 .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
1573 .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
1574 .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
1575 )
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
1576 .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
1577 })
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
1578 .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
1579
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1580 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
1581 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
1582
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
1583 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
1584 }
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
1585
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1586 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
1587 &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
1588 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
1589 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
1590 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
1591 ) -> 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
1592 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
1593 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
1594 None
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1595 } else {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1596 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
1597 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
1598 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
1599 } else {
3e135e79b7f7 headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51975
diff changeset
1600 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
1601 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1602 };
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1603 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
1604 (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
1605 (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
1606 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
1607 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1608 _ => {
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1609 let filtered_revs =
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1610 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
1611 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
1612 &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
1613 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
1614 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
1615 )
51967
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1616 }
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1617 };
69bfd6b242ed head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51966
diff changeset
1618
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
1619 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
1620 // 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
1621 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
1622 .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
1623 .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
1624
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
1625 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
1626 .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
1627 .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
1628 .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
1629 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
1630 } 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
1631 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
1632 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
1633 {
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1634 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
1635 }
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1636
609700e5d8df head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51967
diff changeset
1637 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
1638 .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
1639 .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
1640 .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
1641 .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
1642 .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
1643 .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
1644 }
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
1645 }
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
1646
51394
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1647 fn check_revision(
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1648 index: &hg::index::Index,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1649 rev: UncheckedRevision,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1650 py: Python,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1651 ) -> PyResult<Revision> {
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1652 index
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1653 .check_revision(rev)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1654 .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
1655 }
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1656
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1657 fn inner_headrevsdiff(
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1658 &self,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1659 py: Python,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1660 begin: &PyObject,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1661 end: &PyObject,
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1662 ) -> PyResult<PyObject> {
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1663 let begin = begin.extract::<BaseRevision>(py)?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1664 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
1665 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
1666 let begin =
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1667 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
1668 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
1669 let (removed, added) = index
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1670 .head_revs_diff(begin, end)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1671 .map_err(|e| graph_error(py, e))?;
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1672 let removed: Vec<_> =
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1673 removed.into_iter().map(PyRevision::from).collect();
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1674 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
1675 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
1676 Ok(res)
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1677 }
b01e7d97e167 revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 51260
diff changeset
1678
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1679 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
1680 &self,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1681 new_heads: &[Revision],
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1682 py: Python<'_>,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1683 ) -> 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
1684 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
1685 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
1686 .iter()
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1687 .map(|r| {
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1688 PyBytes::new(
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1689 py,
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1690 index
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1691 .node(*r)
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1692 .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
1693 .as_bytes(),
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1694 )
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1695 .into_object()
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1696 })
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1697 .collect();
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1698 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
1699 *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
1700 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
1701 new_heads_py_list
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1702 }
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1703
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1704 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
1705 &self,
51260
5b4995b40db0 rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51259
diff changeset
1706 new_heads: &[Revision],
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1707 py: Python<'_>,
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1708 ) -> PyList {
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1709 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
1710 .iter()
898674a4dbc7 rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51213
diff changeset
1711 .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
1712 .collect();
51258
9088c6d65ef6 rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51255
diff changeset
1713 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
1714 *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
1715 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
1716 new_heads_py_list
51213
9f876765cbe2 rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51212
diff changeset
1717 }
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1718
51222
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1719 fn inner_ancestors(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1720 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1721 py: Python,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1722 py_revs: &PyTuple,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1723 ) -> 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
1724 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
1725 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
1726 let as_vec: Vec<_> = index
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1727 .ancestors(&revs)
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1728 .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
1729 .iter()
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1730 .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
1731 .collect();
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1732 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
1733 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1734
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1735 fn inner_commonancestorsheads(
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1736 &self,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1737 py: Python,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1738 py_revs: &PyTuple,
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1739 ) -> 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
1740 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
1741 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
1742 let as_vec: Vec<_> = index
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1743 .common_ancestor_heads(&revs)
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1744 .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
1745 .iter()
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1746 .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
1747 .collect();
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1748 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
1749 }
89ce6a49bfeb rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents: 51219
diff changeset
1750
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1751 fn inner_computephasesmapsets(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1752 &self,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1753 py: Python,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1754 py_roots: PyDict,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1755 ) -> 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
1756 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
1757 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
1758 .items_list(py)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1759 .iter(py)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1760 .map(|r| {
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1761 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
1762 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
1763 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
1764 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
1765 .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
1766 Ok((phase?, revs))
51217
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1767 })
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1768 .collect();
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1769 let (len, phase_maps) = index
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1770 .compute_phases_map_sets(roots?)
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1771 .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
1772
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1773 // Ugly hack, but temporary
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1774 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
1775 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
1776 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
1777 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
1778 // 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
1779 // it to `PySet::new`.
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1780 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
1781 for rev in roots {
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1782 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
1783 }
3099f1c68afd rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51403
diff changeset
1784 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
1785 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1786 Ok(PyTuple::new(
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1787 py,
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1788 &[
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1789 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
1790 py_phase_maps.into_object(),
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1791 ],
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1792 )
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1793 .into_object())
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1794 }
c817d9f626d3 rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51216
diff changeset
1795
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1796 fn inner_slicechunktodensity(
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1797 &self,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1798 py: Python,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1799 revs: PyObject,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1800 target_density: f64,
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1801 min_gap_size: usize,
51216
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1802 ) -> 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
1803 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
1804 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
1805 let as_nested_vec =
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1806 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
1807 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
1808 let mut py_chunk = Vec::new();
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1809 for chunk in as_nested_vec {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1810 py_chunk.clear();
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1811 py_chunk.reserve_exact(chunk.len());
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1812 for rev in chunk {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1813 py_chunk.push(
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1814 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
1815 );
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1816 }
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1817 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
1818 }
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1819 // 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
1820 if res.len() == 1 {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1821 Ok(PyTuple::new(py, &res).into_object())
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1822 } else {
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1823 Ok(PyList::new(py, &res).into_object())
8cb31833b486 rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents: 51215
diff changeset
1824 }
51215
0112803e6c01 rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51214
diff changeset
1825 }
51219
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1826
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1827 fn inner_reachableroots2(
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1828 &self,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1829 py: Python,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1830 min_root: UncheckedRevision,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1831 heads: PyObject,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1832 roots: PyObject,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1833 include_path: bool,
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1834 ) -> 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
1835 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
1836 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
1837 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
1838 })?;
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1839 let roots: Result<_, _> = roots
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1840 .iter(py)?
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1841 .map(|r| {
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1842 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
1843 Ok(r) => Ok(UncheckedRevision(r.0)),
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1844 Err(e) => Err(e),
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1845 })
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1846 })
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1847 .collect();
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1848 let as_set = index
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1849 .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
1850 .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
1851 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
1852 .iter()
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1853 .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
1854 .collect();
fc05dd74e907 rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51217
diff changeset
1855 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
1856 }
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1857 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
1858 &self,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1859 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
1860 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
1861 ) -> 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
1862 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
1863 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
1864 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
1865 .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
1866 .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
1867 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
1868 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
1869 })?;
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1870 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
1871 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1872 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1873
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1874 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
1875 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
1876 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
1877 opener: PyObject,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1878 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
1879 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
1880 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
1881 _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
1882 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
1883 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
1884 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
1885 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
1886 _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
1887 _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
1888 revlog_type: usize,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1889 ) -> 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
1890 let vfs = Box::new(PyVfs::new(py, opener)?);
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1891 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
1892 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
1893 .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
1894 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
1895 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
1896 .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
1897 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
1898 .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
1899 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
1900 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
1901 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
1902 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
1903 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
1904 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
1905 inline,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1906 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
1907 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
1908 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
1909 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1910 // 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
1911 let (buf, bytes) = unsafe { mmap_keeparound(py, 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
1912 let index = hg::index::Index::new(bytes, options.index_header())
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1913 .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
1914 let core = CoreInnerRevlog::new(
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1915 vfs,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1916 index,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1917 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
1918 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
1919 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
1920 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
1921 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
1922 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1923 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
1924 py,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1925 core,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1926 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
1927 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
1928 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
1929 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
1930 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
1931 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
1932 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
1933 )
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1934 }
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
1935 }
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
1936
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1937 py_class!(pub class NodeTree |py| {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1938 data nt: RefCell<CoreNodeTree>;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1939 data index: RefCell<UnsafePyLeaked<PySharedIndex>>;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1940
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1941 def __new__(_cls, index: PyObject) -> PyResult<NodeTree> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1942 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
1943 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
1944 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
1945 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1946
51248
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
1947 /// 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
1948 ///
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
1949 /// 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
1950 /// 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
1951 /// 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
1952 /// (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
1953 /// been meanwhile mutated.
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
1954 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
1955 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
1956 // 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
1957 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
1958 // 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
1959 // - 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
1960 // - 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
1961 // 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
1962 // 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
1963 Ok(result.is_err())
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
1964 }
0409bd6ba663 rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents: 51247
diff changeset
1965
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1966 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
1967 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
1968 // 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
1969 let index = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1970
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1971 let rev = UncheckedRevision(rev.0);
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1972 let rev = index
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1973 .check_revision(rev)
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1974 .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
1975 if rev == NULL_REVISION {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1976 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
1977 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1978
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
1979 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
1980 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
1981 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
1982
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1983 Ok(py.None())
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1984 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1985
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1986 /// 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
1987 ///
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1988 /// 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
1989 /// 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
1990 def prefix_rev_lookup(
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1991 &self,
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1992 node_prefix: PyBytes
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1993 ) -> PyResult<Option<PyRevision>> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1994 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
1995 .map_err(|_| PyErr::new::<ValueError, _>(
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1996 py,
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1997 format!("Invalid node or prefix {:?}",
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1998 node_prefix.as_object()))
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
1999 )?;
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2000
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2001 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
2002 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
2003 // 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
2004 let index = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2005
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2006 Ok(nt.find_bin(index, prefix)
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2007 .map_err(|e| nodemap_error(py, e))?
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2008 .map(|r| r.into())
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2009 )
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2010 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2011
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2012 def shortest(&self, node: PyBytes) -> PyResult<usize> {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2013 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
2014 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
2015 // 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
2016 let idx = &*unsafe { leaked.try_borrow(py)? };
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2017 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
2018 {
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2019 Ok(Some(l)) => Ok(l),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2020 Ok(None) => Err(revlog_error(py)),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2021 Err(e) => Err(nodemap_error(py, e)),
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2022 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2023 }
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2024 });
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2025
52163
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2026 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
2027 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2028 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
2029 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2030 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
2031 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2032
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2033 /// # Safety
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2034 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2035 /// 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
2036 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
2037 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
2038 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
2039 ) -> T
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2040 where
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2041 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
2042 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2043 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
2044 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
2045 } else {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2046 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
2047 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2048 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2049
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2050 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
2051 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
2052 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
2053 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
2054 ) -> 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
2055 where
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2056 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
2057 &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
2058 ) -> 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
2059 {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2060 // 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
2061 // 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
2062 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2063 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
2064 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
2065 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
2066 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2067 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
2068 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
2069 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
2070 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
2071 // 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
2072 // 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
2073 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
2074 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2075 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2076
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2077 /// 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
2078 /// 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
2079 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
2080 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
2081 _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
2082 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
2083 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
2084 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
2085 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2086
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2087 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
2088 /// # Safety
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2089 ///
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2090 /// `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
2091 /// 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
2092 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2093 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
2094 Self {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2095 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
2096 _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
2097 len,
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2098 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
2099 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
2100 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2101 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2102
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2103 /// 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
2104 /// 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
2105 /// written.
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2106 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2107 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
2108 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
2109 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2110 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2111
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2112 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
2113 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
2114
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2115 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2116 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
2117 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
2118 unsafe {
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2119 // 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
2120 // 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
2121 // [`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
2122 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
2123 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
2124 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2125 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
2126 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2127
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2128 #[inline]
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2129 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
2130 // 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
2131 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
2132 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
2133 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
2134 "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
2135 );
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2136 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
2137 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2138 }
7346f93be7a4 revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents: 52158
diff changeset
2139
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2140 fn revlog_error(py: Python) -> PyErr {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2141 match py
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2142 .import("mercurial.error")
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2143 .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
2144 {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2145 Err(e) => e,
47305
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2146 Ok(cls) => PyErr::from_instance(
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2147 py,
33e7508b0ae9 hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47268
diff changeset
2148 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
2149 ),
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2150 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2151 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2152
51212
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2153 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
2154 // ParentOutOfRange is currently the only alternative
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2155 // 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
2156 PyErr::new::<ValueError, _>(py, "parent out of range")
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2157 }
a7bba7df9189 rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 51211
diff changeset
2158
51196
44fbb7dfb563 rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents: 51195
diff changeset
2159 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
2160 PyErr::new::<ValueError, _>(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2161 py,
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2162 format!(
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2163 "Inconsistency: Revision {} found in nodemap \
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2164 is not in revlog index",
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2165 rev
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2166 ),
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2167 )
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2168 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2169
51197
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2170 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
2171 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
2172 py,
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2173 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
2174 )
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2175 }
bc4d83047c6c rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents: 51196
diff changeset
2176
44506
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2177 /// Standard treatment of NodeMapError
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2178 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
2179 match err {
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2180 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
2181 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
2182 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2183 }
26dd35ac59b8 rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents: 44503
diff changeset
2184
43961
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2185 /// 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
2186 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
2187 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
2188 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
2189 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
2190 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
2191
51246
2966b88d4531 rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents: 51245
diff changeset
2192 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
2193 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
2194
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2195 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
2196 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
2197 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
2198
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2199 Ok(m)
b69d5f3a41d0 rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents: 43945
diff changeset
2200 }