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