annotate rust/hg-cpython/src/revlog.rs @ 52302:72bc29f01570

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