Mercurial > public > mercurial-scm > hg
annotate rust/hg-cpython/src/revlog.rs @ 52174:bcd4962e0df9
rust-revlog: don't create an in-memory nodemap for filelogs from Python
Explanations inline.
Benchmarks from this change affect positively the only repo that showed this
being a problem:
```
### data-env-vars.name = mozilla-try-2024-03-26-ds2-pnm
# benchmark.name = hg.command.cat
# bin-env-vars.hg.flavor = rust
# bin-env-vars.hg.py-re2-module = default
# benchmark.variants.files = all-root
# benchmark.variants.output = plain
# benchmark.variants.rev = tip
default: 62.848869 ~~~~~
before-this-patch: 58.113051 (-7.54%, -4.74)
this-patch: 57.407533 (-8.66%, -5.44)
### data-env-vars.name = mozilla-try-2024-03-26-ds2-pnm
# benchmark.name = hg.command.log
# bin-env-vars.hg.flavor = rust
# bin-env-vars.hg.py-re2-module = default
# benchmark.variants.limit-rev = 10
# benchmark.variants.patch = yes
# benchmark.variants.rev = none
default: 3.173532 ~~~~~
before-this-patch: 3.543591 (+11.66%, +0.37)
this-patch: 3.297235 (+3.90%, +0.12)
```
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 31 Jul 2024 13:35:54 +0200 |
parents | 72bc29f01570 |
children | c90e0f65896e |
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}, |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
46 sync::atomic::{AtomicBool, 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, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
140 "Nodemap data buffer has an invalid memory representation" |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
141 .to_string(), |
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 |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
145 Ok((buf, Box::new(bytes))) |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
146 } |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
147 |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
148 fn py_tuple_to_revision_data_params( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
149 py: Python, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
150 tuple: PyTuple, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
151 ) -> PyResult<RevisionDataParams> { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
152 if tuple.len(py) < 8 { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
153 // this is better than the panic promised by tup.get_item() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
154 return Err(PyErr::new::<IndexError, _>( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
155 py, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
156 "tuple index out of range", |
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 } |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
159 let offset_or_flags: u64 = tuple.get_item(py, 0).extract(py)?; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
160 let node_id = tuple |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
161 .get_item(py, 7) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
162 .extract::<PyBytes>(py)? |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
163 .data(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
164 .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
|
165 .expect("nodeid should be set"); |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
166 let flags = (offset_or_flags & 0xFFFF) as u16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
167 let data_offset = offset_or_flags >> 16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
168 Ok(RevisionDataParams { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
169 flags, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
170 data_offset, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
171 data_compressed_length: tuple.get_item(py, 1).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
172 data_uncompressed_length: tuple.get_item(py, 2).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
173 data_delta_base: tuple.get_item(py, 3).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
174 link_rev: tuple.get_item(py, 4).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
175 parent_rev_1: tuple.get_item(py, 5).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
176 parent_rev_2: tuple.get_item(py, 6).extract(py)?, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
177 node_id, |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
178 ..Default::default() |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
179 }) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
180 } |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
181 fn revision_data_params_to_py_tuple( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
182 py: Python, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
183 params: RevisionDataParams, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
184 ) -> PyTuple { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
185 PyTuple::new( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
186 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
187 &[ |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
188 params.data_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
189 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
190 .data_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
191 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
192 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
193 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
194 .data_uncompressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
195 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
196 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
197 params.data_delta_base.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
198 params.link_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
199 params.parent_rev_1.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
200 params.parent_rev_2.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
201 PyBytes::new(py, ¶ms.node_id) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
202 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
203 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
204 params._sidedata_offset.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
205 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
206 ._sidedata_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
207 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
208 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
209 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
210 .data_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
211 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
212 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
213 params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
214 ._sidedata_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
215 .into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
216 .into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
217 params._rank.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
218 ], |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
219 ) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
220 } |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
221 |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
222 struct PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
223 py: Python<'p>, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
224 dict: PyDict, |
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 |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
227 impl<'p> SnapshotsCache for PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
228 fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
229 &mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
230 rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
231 value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
232 ) -> Result<(), RevlogError> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
233 let pyvalue = value.into_py_object(self.py).into_object(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
234 match self.dict.get_item(self.py, rev) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
235 Some(obj) => obj |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
236 .extract::<PySet>(self.py) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
237 .and_then(|set| set.add(self.py, pyvalue)), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
238 None => PySet::new(self.py, vec![pyvalue]) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
239 .and_then(|set| self.dict.set_item(self.py, rev, set)), |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
240 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
241 .map_err(|_| { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
242 RevlogError::Other(HgError::unsupported( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
243 "Error in Python caches handling", |
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 } |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
248 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
249 // There are no static generics in Rust (because their implementation is hard, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
250 // I'm guessing it's due to different compilation stages, etc.). |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
251 // So manually generate all three caches and use them in `with_filelog_cache`. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
252 static DELTA_CONFIG_CACHE: OnceLock<(PyObject, RevlogDeltaConfig)> = |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
253 OnceLock::new(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
254 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
|
255 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
|
256 static FEATURE_CONFIG_CACHE: OnceLock<(PyObject, RevlogFeatureConfig)> = |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
257 OnceLock::new(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
258 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
259 /// Cache the first conversion from Python -> Rust config for all filelogs to |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
260 /// save on conversion time when called in a loop. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
261 fn with_filelog_cache<T: Copy>( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
262 py: Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
263 py_config: &PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
264 revlog_type: RevlogType, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
265 cache: &OnceLock<(PyObject, T)>, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
266 callback: impl Fn() -> PyResult<T>, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
267 ) -> PyResult<T> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
268 let mut was_cached = false; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
269 if revlog_type == RevlogType::Filelog { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
270 if let Some((cached_py_config, rust_config)) = cache.get() { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
271 was_cached = true; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
272 // All filelogs in a given repository *most likely* have the |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
273 // exact same config, but it's not impossible that some extensions |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
274 // do some magic with configs or that this code will be used |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
275 // for longer-running processes. So compare the source `PyObject` |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
276 // in case the source changed, at the cost of some overhead. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
277 // We can't use `py_config.eq(cached_py_config)` because all config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
278 // objects are different in Python and `a is b` is false. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
279 if py_config.compare(py, cached_py_config)?.is_eq() { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
280 return Ok(*rust_config); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
284 let config = callback()?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
285 // Do not call the lock unnecessarily if it's already been set. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
286 if !was_cached && revlog_type == RevlogType::Filelog { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
287 cache.set((py_config.clone_ref(py), config)).ok(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
288 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
289 Ok(config) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
292 fn extract_delta_config( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
293 py: Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
294 py_config: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
295 revlog_type: RevlogType, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
296 ) -> PyResult<RevlogDeltaConfig> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
297 let get_delta_config = || { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
298 let max_deltachain_span = py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
299 .getattr(py, "max_deltachain_span")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
300 .extract::<i64>(py)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
301 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
302 let revlog_delta_config = RevlogDeltaConfig { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
303 general_delta: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
304 .getattr(py, "general_delta")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
305 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
306 sparse_revlog: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
307 .getattr(py, "sparse_revlog")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
308 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
309 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
|
310 .getattr(py, "max_chain_len")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
311 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
312 max_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
|
313 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
314 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
315 Some(max_deltachain_span as u64) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
316 }, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
317 upper_bound_comp: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
318 .getattr(py, "upper_bound_comp")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
319 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
320 delta_both_parents: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
321 .getattr(py, "delta_both_parents")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
322 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
323 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
|
324 .getattr(py, "candidate_group_chunk_size")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
325 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
326 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
|
327 lazy_delta: py_config.getattr(py, "lazy_delta")?.extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
328 lazy_delta_base: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
329 .getattr(py, "lazy_delta_base")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
330 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
331 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
332 Ok(revlog_delta_config) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
333 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
334 with_filelog_cache( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
335 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
336 &py_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
337 revlog_type, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
338 &DELTA_CONFIG_CACHE, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
339 get_delta_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
343 fn extract_data_config( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
344 py: Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
345 py_config: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
346 revlog_type: RevlogType, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
347 ) -> PyResult<RevlogDataConfig> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
348 let get_data_config = || { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
349 Ok(RevlogDataConfig { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
350 try_pending: py_config.getattr(py, "try_pending")?.extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
351 try_split: py_config.getattr(py, "try_split")?.extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
352 check_ambig: py_config.getattr(py, "check_ambig")?.extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
353 mmap_large_index: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
354 .getattr(py, "mmap_large_index")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
355 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
356 mmap_index_threshold: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
357 .getattr(py, "mmap_index_threshold")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
358 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
359 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
|
360 .getattr(py, "chunk_cache_size")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
361 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
362 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
|
363 .getattr(py, "uncompressed_cache_factor")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
364 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
365 uncompressed_cache_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
|
366 .getattr(py, "uncompressed_cache_count")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
367 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
368 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
|
369 .getattr(py, "with_sparse_read")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
370 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
371 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
|
372 .getattr(py, "sr_density_threshold")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
373 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
374 sr_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
|
375 .getattr(py, "sr_min_gap_size")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
376 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
377 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
|
378 .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
|
379 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
380 }) |
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
383 with_filelog_cache( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
384 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
385 &py_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
386 revlog_type, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
387 &DATA_CONFIG_CACHE, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
388 get_data_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
389 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
390 } |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
391 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
392 fn extract_feature_config( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
393 py: Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
394 py_config: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
395 revlog_type: RevlogType, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
396 ) -> PyResult<RevlogFeatureConfig> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
397 let get_feature_config = || { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
398 let engine_bytes = &py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
399 .getattr(py, "compression_engine")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
400 .extract::<PyBytes>(py)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
401 let compression_engine = engine_bytes.data(py); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
402 let compression_engine = match compression_engine { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
403 b"zlib" => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
404 let compression_options = &py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
405 .getattr(py, "compression_engine_options")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
406 .extract::<PyDict>(py)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
407 let zlib_level = compression_options |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
408 .get_item(py, PyBytes::new(py, &b"zlib.level"[..])); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
409 let level = if let Some(level) = zlib_level { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
410 if level.is_none(py) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
411 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
412 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
413 Some(level.extract(py)?) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
414 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
415 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
416 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
417 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
418 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
|
419 if let Some(level) = level { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
420 engine |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
421 .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
|
422 .expect("invalid compression level from Python"); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
423 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
424 engine |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
425 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
426 b"zstd" => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
427 let compression_options = &py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
428 .getattr(py, "compression_engine_options")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
429 .extract::<PyDict>(py)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
430 let zstd_level = compression_options |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
431 .get_item(py, PyBytes::new(py, &b"zstd.level"[..])); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
432 let level = if let Some(level) = zstd_level { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
433 if level.is_none(py) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
434 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
435 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
436 Some(level.extract(py)?) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
437 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
438 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
439 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
|
440 .get_item(py, PyBytes::new(py, &b"level"[..])); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
441 if let Some(level) = level { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
442 if level.is_none(py) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
443 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
444 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
445 Some(level.extract(py)?) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
446 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
447 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
448 None |
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 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
451 CompressionConfig::zstd(level) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
452 .expect("invalid compression level from Python") |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
453 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
454 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
|
455 e => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
456 return Err(PyErr::new::<ValueError, _>( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
457 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
458 format!( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
459 "invalid compression engine {}", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
460 String::from_utf8_lossy(e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
465 let revlog_feature_config = RevlogFeatureConfig { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
466 compression_engine, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
467 censorable: py_config.getattr(py, "censorable")?.extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
468 has_side_data: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
469 .getattr(py, "has_side_data")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
470 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
471 compute_rank: py_config |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
472 .getattr(py, "compute_rank")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
473 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
474 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
|
475 .getattr(py, "canonical_parent_order")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
476 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
477 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
|
478 .getattr(py, "enable_ellipsis")? |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
479 .extract(py)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
480 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
481 Ok(revlog_feature_config) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
482 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
483 with_filelog_cache( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
484 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
485 &py_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
486 revlog_type, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
487 &FEATURE_CONFIG_CACHE, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
488 get_feature_config, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
492 fn revlog_error_from_msg(py: Python, e: impl ToString) -> PyErr { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
493 let msg = e.to_string(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
494 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
495 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
|
496 .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
|
497 .and_then(|m| m.get(py, "RevlogError")) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
498 { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
499 Err(e) => e, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
500 Ok(cls) => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
501 let msg = PyBytes::new(py, msg.as_bytes()); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
502 PyErr::from_instance( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
503 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 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
|
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
510 py_class!(pub class ReadingContextManager |py| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
511 data inner_revlog: RefCell<InnerRevlog>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
512 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
513 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
|
514 let res = self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
515 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
516 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
517 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
518 .enter_reading_context() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
519 .map_err(|e| revlog_error_from_msg(py, e)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
520 if let Err(e) = res { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
521 // `__exit__` is not called from Python if `__enter__` fails |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
522 self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
523 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
524 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
525 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
526 .exit_reading_context(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
527 return Err(e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
528 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
529 Ok(py.None()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
532 def __exit__( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
533 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
534 ty: Option<PyType>, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
535 value: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
536 traceback: PyObject |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
537 ) -> PyResult<PyObject> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
538 // unused arguments, keep clippy from complaining without adding |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
539 // a general rule |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
540 let _ = ty; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
541 let _ = value; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
542 let _ = traceback; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
543 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
544 self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
545 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
546 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
547 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
548 .exit_reading_context(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
549 Ok(py.None()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
553 // Only used from Python *tests* |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
554 py_class!(pub class PyFileHandle |py| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
555 data inner_file: RefCell<std::os::fd::RawFd>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
556 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
557 def tell(&self) -> PyResult<PyObject> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
558 let locals = PyDict::new(py); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
559 locals.set_item(py, "os", py.import("os")?)?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
560 locals.set_item(py, "fd", *self.inner_file(py).borrow())?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
561 let f = py.eval("os.fdopen(fd)", None, Some(&locals))?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
562 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
563 // Prevent Python from closing the file after garbage collecting. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
564 // This is fine since Rust is still holding on to the actual File. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
565 // (and also because it's only used in tests). |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
566 std::mem::forget(f.clone_ref(py)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
567 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
568 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
|
569 let res = py.eval("f.tell()", None, Some(&locals))?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
570 Ok(res) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
574 /// Wrapper around a Python transaction object, to keep `hg-core` oblivious |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
575 /// of the fact it's being called from Python. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
576 pub struct PyTransaction { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
577 inner: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
580 impl PyTransaction { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
581 pub fn new(inner: PyObject) -> Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
582 Self { inner } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
586 impl Clone for PyTransaction { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
587 fn clone(&self) -> Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
588 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
589 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
590 Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
591 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
|
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
596 impl Transaction for PyTransaction { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
597 fn add(&mut self, file: impl AsRef<std::path::Path>, offset: usize) { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
598 let gil = &Python::acquire_gil(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
599 let py = gil.python(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
600 let file = PyBytes::new(py, &get_bytes_from_path(file.as_ref())); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
601 self.inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
602 .call_method(py, "add", (file, offset), None) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
603 .expect("transaction add failed"); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
607 py_class!(pub class WritingContextManager |py| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
608 data inner_revlog: RefCell<InnerRevlog>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
609 data transaction: RefCell<PyTransaction>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
610 data data_end: Cell<Option<usize>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
611 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
612 def __enter__(&self) -> PyResult<PyObject> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
613 let res = self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
614 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
615 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
616 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
617 .enter_writing_context( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
618 self.data_end(py).get(), |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
619 &mut *self.transaction(py).borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
620 ).map_err(|e| revlog_error_from_msg(py, e)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
621 if let Err(e) = res { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
622 // `__exit__` is not called from Python if `__enter__` fails |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
623 self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
624 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
625 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
626 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
627 .exit_writing_context(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
628 return Err(e) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
629 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
630 Ok(py.None()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
633 def __exit__( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
634 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
635 ty: Option<PyType>, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
636 value: PyObject, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
637 traceback: PyObject |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
638 ) -> PyResult<PyObject> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
639 // unused arguments, keep clippy from complaining without adding |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
640 // a general rule |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
641 let _ = ty; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
642 let _ = value; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
643 let _ = traceback; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
644 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
645 self.inner_revlog(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
646 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
647 .inner(py) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
648 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
649 .exit_writing_context(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
650 Ok(py.None()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 }); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
653 |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
654 struct PyFnCache { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
655 fncache: PyObject, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
656 } |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
657 impl PyFnCache { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
658 fn new(fncache: PyObject) -> Self { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
659 Self { fncache } |
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 |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
663 impl Clone for PyFnCache { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
664 fn clone(&self) -> Self { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
665 let gil = Python::acquire_gil(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
666 let py = gil.python(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
667 Self { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
668 fncache: self.fncache.clone_ref(py), |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
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 |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
673 /// Cache whether the fncache is loaded to avoid Python round-trip every time. |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
674 /// Once the fncache is loaded, it stays loaded unless we're in a very |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
675 /// long-running process, none of which we actually support for now. |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
676 static FN_CACHE_IS_LOADED: AtomicBool = AtomicBool::new(false); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
677 |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
678 impl FnCache for PyFnCache { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
679 fn is_loaded(&self) -> bool { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
680 if FN_CACHE_IS_LOADED.load(Ordering::Relaxed) { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
681 return true; |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
682 } |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
683 let gil = Python::acquire_gil(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
684 let py = gil.python(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
685 // TODO raise in case of error? |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
686 let is_loaded = self |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
687 .fncache |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
688 .getattr(py, "is_loaded") |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
689 .ok() |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
690 .map(|o| { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
691 o.extract::<bool>(py) |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
692 .expect("is_loaded returned something other than a bool") |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
693 }) |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
694 .unwrap_or(false); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
695 if is_loaded { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
696 FN_CACHE_IS_LOADED.store(true, Ordering::Relaxed); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
697 } |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
698 is_loaded |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
699 } |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
700 fn add(&self, path: &std::path::Path) { |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
701 let gil = Python::acquire_gil(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
702 let py = gil.python(); |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
703 // TODO raise in case of error? |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
704 self.fncache |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
705 .call_method( |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
706 py, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
707 "add", |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
708 (PyBytes::new(py, &get_bytes_from_path(path)),), |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
709 None, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
710 ) |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
711 .ok(); |
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 } |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
714 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
715 py_class!(pub class InnerRevlog |py| { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
716 @shared data inner: CoreInnerRevlog; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
717 data nt: RefCell<Option<CoreNodeTree>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
718 data docket: RefCell<Option<PyObject>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
719 // Holds a reference to the mmap'ed persistent nodemap data |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
720 data nodemap_mmap: RefCell<Option<PyBuffer>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
721 // Holds a reference to the mmap'ed persistent index data |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
722 data index_mmap: RefCell<PyBuffer>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
723 data head_revs_py_list: RefCell<Option<PyList>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
724 data head_node_ids_py_list: RefCell<Option<PyList>>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
725 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
|
726 data 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
|
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(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
770 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
|
771 } |
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 @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
|
774 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
|
775 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
|
776 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
777 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
778 @property def 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
|
779 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
|
780 } |
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 @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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 } |
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 @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
|
794 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
|
795 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
796 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
|
797 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
|
798 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
806 None |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
807 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
808 let handle = |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
809 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
|
810 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
811 ( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
812 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
|
813 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
|
814 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
|
815 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
816 ).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
|
817 ) |
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 @_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
|
824 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
825 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
|
826 ) -> PyResult<()> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
827 *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
|
828 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
|
829 None => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
830 // 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
|
831 // 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
|
832 // 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
|
833 self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
834 .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
|
835 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
836 .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
|
837 .lock() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
838 .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
|
839 .take(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
840 }, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
841 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
|
842 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
|
843 self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
844 .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
|
845 .borrow() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
846 .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
|
847 .lock() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
848 .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
|
849 .take(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
850 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
|
851 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
852 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
|
853 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
|
854 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
|
855 // 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
|
856 // checked |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
857 let 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
|
858 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
|
859 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
|
860 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
|
861 .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
|
862 .lock() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
863 .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
|
864 *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
|
865 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
|
866 } |
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 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
869 } |
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 @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
|
872 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
|
873 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
874 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
875 @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
|
876 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
877 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
|
878 ) -> PyResult<()> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
879 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
|
880 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
|
881 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
882 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
883 } |
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 @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
|
886 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
887 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
|
888 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
889 &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
|
890 ) |
44503
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
891 ) |
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 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
894 @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
|
895 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
896 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
|
897 ) -> PyResult<()> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
898 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
|
899 value |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
900 .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
|
901 .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
|
902 .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
|
903 ).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
|
904 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
|
905 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
906 } |
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 @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
|
909 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
|
910 } |
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 @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
|
913 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
|
914 } |
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 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
|
917 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
|
918 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
919 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 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
|
924 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
925 &[ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
926 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
|
927 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
|
928 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
|
929 ] |
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 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
|
932 } |
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 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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 .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
|
940 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
|
941 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
|
942 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
|
943 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
944 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
|
945 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
946 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
947 ( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
948 header, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
949 PyBytes::new(py, 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
|
950 ).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
|
951 ) |
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 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
|
955 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
|
956 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
957 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
|
958 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
959 } |
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 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
|
962 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
963 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
|
964 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
|
965 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
|
966 ) -> 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
|
967 // 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
|
968 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
|
969 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
|
970 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 ) |
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 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
|
978 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
979 _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
|
980 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
|
981 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
|
982 ) -> 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
|
983 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
|
984 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
|
985 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
|
986 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
|
987 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
|
988 }, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
989 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
|
990 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
991 let 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
|
992 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
|
993 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
|
994 .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
|
995 .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
|
996 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
|
997 } |
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 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
|
1000 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1001 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
|
1002 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
|
1003 ) -> 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
|
1004 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
|
1005 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
|
1006 .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
|
1007 .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
|
1008 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
|
1009 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
|
1010 } |
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 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
|
1013 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1014 _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
|
1015 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
|
1016 ) -> 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
|
1017 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
|
1018 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
|
1019 inner |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1020 .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
|
1021 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
|
1022 Ok(()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1023 }).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
|
1024 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
|
1025 } |
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 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
|
1028 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1029 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
|
1030 ) -> 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
|
1031 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
|
1032 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
|
1033 .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
|
1034 .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
|
1035 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
|
1036 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
|
1037 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1038 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1039 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
|
1040 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1041 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
|
1042 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
|
1043 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
|
1044 _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
|
1045 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
|
1046 _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
|
1047 _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
|
1048 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
|
1049 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
|
1050 _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
|
1051 ) -> 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1062 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
|
1063 transaction, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1064 &entry, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1065 (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
|
1066 offset, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1067 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
|
1068 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
|
1069 ).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
|
1070 .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
|
1071 ) |
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 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
|
1075 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
|
1076 .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
|
1077 .delay() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1078 .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
|
1079 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
|
1080 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1081 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1082 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
|
1083 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
|
1084 .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
|
1085 .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
|
1086 .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
|
1087 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
|
1088 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
|
1089 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
|
1090 }, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1091 None => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1092 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
|
1093 } |
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 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1096 ( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1097 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
|
1098 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
|
1099 ).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
|
1100 ) |
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 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
|
1104 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
|
1105 .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
|
1106 .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
|
1107 .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
|
1108 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
|
1109 } |
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 // -- 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
|
1112 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1113 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
|
1114 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
|
1115 // 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
|
1116 // 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
|
1117 // 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
|
1118 // seems to work quite well for all measured purposes so far. |
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 // |
bcd4962e0df9
rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52172
diff
changeset
|
1120 // TODO build an in-memory nodemap if more than 4 queries to the same |
bcd4962e0df9
rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52172
diff
changeset
|
1121 // revlog are made? |
bcd4962e0df9
rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52172
diff
changeset
|
1122 if !*self.use_persistent_nodemap(py) { |
bcd4962e0df9
rust-revlog: don't create an in-memory nodemap for filelogs from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52172
diff
changeset
|
1123 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
|
1124 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
|
1125 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
|
1126 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
|
1127 } |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1128 let 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
|
1129 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
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1135 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1136 /// 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
|
1137 /// 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
|
1138 /// |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1139 /// 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
|
1140 /// 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
|
1141 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
|
1142 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
|
1143 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1144 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1145 /// 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
|
1146 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
|
1147 // 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
|
1148 // 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
|
1149 // 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
|
1150 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
|
1151 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1152 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1153 /// 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
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 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
|
1159 { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1160 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
|
1161 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
|
1162 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
|
1163 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1164 } |
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 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
|
1167 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1168 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
|
1169 ) -> 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
|
1170 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
|
1171 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
|
1172 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
|
1173 |
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 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
|
1175 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
|
1176 |
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 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
|
1178 .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
|
1179 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
|
1180 )?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1181 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1182 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
|
1183 // 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
|
1184 .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
|
1185 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
|
1186 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1187 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
|
1188 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1189 })) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1190 .map_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
|
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 } |
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 /// 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
|
1195 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
|
1196 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
|
1197 // 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
|
1198 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
|
1199 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
|
1200 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1201 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
|
1202 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
|
1203 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1204 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
|
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 // 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
|
1207 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
|
1208 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
|
1209 .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
|
1210 .index |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1211 .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
|
1212 .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
|
1213 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
|
1214 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
|
1215 .borrow_mut() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1216 .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
|
1217 .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
|
1218 .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
|
1219 .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
|
1220 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
|
1221 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1222 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1223 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
|
1224 // __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
|
1225 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
|
1226 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
|
1227 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1228 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
|
1229 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
|
1230 }; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1231 let 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
|
1232 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
|
1233 .index |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1234 .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
|
1235 .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
|
1236 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
|
1237 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1238 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
|
1239 .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
|
1240 .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
|
1241 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
|
1242 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
|
1243 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
|
1244 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
|
1245 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
|
1246 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
|
1247 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1248 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1249 /// 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
|
1250 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
|
1251 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
|
1252 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
|
1253 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1254 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1255 /// return the 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
|
1256 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
|
1257 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1258 *args, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1259 **_kw |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1260 ) -> 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
|
1261 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
|
1262 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
|
1263 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1264 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1265 /// 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
|
1266 /// 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
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1276 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1277 /// 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
|
1278 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
|
1279 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
|
1280 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
|
1281 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
|
1282 |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
|
1283 )?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1284 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
|
1285 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
|
1286 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1287 |
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 /// 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
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1296 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1297 /// 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
|
1298 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
|
1299 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1300 *args, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1301 **_kw |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1302 ) -> 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
|
1303 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
|
1304 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
|
1305 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
|
1306 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1307 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1308 /// reachableroots |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1309 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
|
1310 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
|
1311 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1312 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
|
1313 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
|
1314 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
|
1315 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
|
1316 )?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1317 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
|
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1320 /// 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
|
1321 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
|
1322 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
|
1323 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
|
1324 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
|
1325 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
|
1326 _ => 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
|
1327 }?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1328 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
|
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1331 /// 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
|
1332 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
|
1333 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
|
1334 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
|
1335 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1336 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1337 /// get 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
|
1338 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
|
1339 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
|
1340 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1341 &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
|
1342 &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
|
1343 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
|
1344 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1345 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1346 /// 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
|
1347 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
|
1348 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
|
1349 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
|
1350 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1351 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1352 /// 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
|
1353 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
|
1354 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
|
1355 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
|
1356 // 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
|
1357 // 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
|
1358 // 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
|
1359 // caches. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1360 let 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
|
1361 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
|
1362 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
|
1363 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1364 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1365 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
|
1366 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
|
1367 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
|
1368 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
|
1369 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
|
1370 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
|
1371 &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
|
1372 ).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
|
1373 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
|
1374 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1375 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1376 /// 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
|
1377 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
|
1378 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
|
1379 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
|
1380 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
|
1381 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
|
1382 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
|
1383 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
|
1384 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1385 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
|
1386 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
|
1387 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
|
1388 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
|
1389 })?) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1390 } 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
|
1391 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
|
1392 .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
|
1393 .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
|
1394 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
|
1395 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
|
1396 ).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
|
1397 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
|
1398 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1399 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1400 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
|
1401 Ok( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1402 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
|
1403 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1404 &[ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1405 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
|
1406 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
|
1407 ] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1408 ).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 } |
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 /// 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
|
1413 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
|
1414 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
|
1415 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 )?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1420 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
|
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 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1423 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
|
1424 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
|
1425 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1426 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1427 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
|
1428 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
|
1429 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
|
1430 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1431 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1432 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
|
1433 // 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
|
1434 // 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
|
1435 // 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
|
1436 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
|
1437 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
|
1438 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
|
1439 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1440 Err(_) => { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1441 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
|
1442 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
|
1443 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
|
1444 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1445 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1446 } |
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 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
|
1449 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
|
1450 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1451 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1452 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
|
1453 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
|
1454 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1455 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1456 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
|
1457 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1458 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
|
1459 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
|
1460 ) -> 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
|
1461 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
|
1462 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1463 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1464 @property |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1465 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
|
1466 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
|
1467 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
|
1468 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1469 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1470 @property |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1471 def _index_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
|
1472 // 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
|
1473 // 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
|
1474 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
|
1475 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
|
1476 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1477 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1478 @property |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1479 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
|
1480 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
|
1481 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1482 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1483 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1484 }); |
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 /// 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
|
1487 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
|
1488 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
|
1489 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
|
1490 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
|
1491 } |
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
|
1492 /// 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
|
1493 /// 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
|
1494 /// 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
|
1495 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
|
1496 &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
|
1497 py: Python, |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
1498 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
|
1499 ) -> 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
|
1500 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
|
1501 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
|
1502 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
|
1503 // 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
|
1504 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
|
1505 .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
|
1506 } |
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 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
|
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 |
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 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
|
1511 &'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
|
1512 py: Python<'a>, |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
1513 ) -> 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
|
1514 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
|
1515 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
|
1516 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
|
1517 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
|
1518 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
|
1519 } |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
1520 Ok(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
|
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 |
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1523 /// 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
|
1524 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
|
1525 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
|
1526 .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
|
1527 .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
|
1528 .take() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1529 .expect("nodetree should exist"); |
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1530 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
|
1531 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1532 // 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
|
1533 // scratch |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1534 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
|
1535 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
|
1536 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
|
1537 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1538 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
|
1539 assert_eq!(readonly.len(), 0); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1540 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1541 bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1542 } else { |
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 }; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1545 |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1546 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
|
1547 Ok(bytes) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
1548 } |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1549 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1550 /// 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
|
1551 /// (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
|
1552 fn inner_nodemap_data_incremental( |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1553 &self, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1554 py: Python, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1555 ) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1556 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
|
1557 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
|
1558 Some(d) => d, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1559 None => return Ok(py.None()), |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1560 }; |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1561 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1562 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
|
1563 .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
|
1564 .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
|
1565 .take() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1566 .expect("nodetree should exist"); |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1567 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
|
1568 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
|
1569 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
|
1570 |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1571 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
|
1572 .to_py_object(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1573 .into_object()) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
1574 } |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1575 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1576 /// 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
|
1577 /// 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
|
1578 fn inner_update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1579 &self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1580 py: Python, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1581 docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1582 nm_data: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1583 ) -> 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
|
1584 // 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
|
1585 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
|
1586 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
|
1587 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
|
1588 |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
1589 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
|
1590 |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
1591 let data_tip = docket |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
1592 .getattr(py, "tip_rev")? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
1593 .extract::<BaseRevision>(py)? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
1594 .into(); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1595 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
|
1596 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
|
1597 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
|
1598 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
|
1599 })?; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1600 let current_tip = idx.len(); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1601 |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
1602 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
|
1603 let rev = Revision(r); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1604 // 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
|
1605 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
|
1606 .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
|
1607 } |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1608 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1609 *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
|
1610 |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1611 Ok(py.None()) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
1612 } |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1613 |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1614 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
|
1615 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
|
1616 Ok(match key.extract::<BaseRevision>(py) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1617 Ok(key_as_int) => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1618 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
|
1619 RevisionDataParams::default() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1620 } else { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1621 let rev = UncheckedRevision(key_as_int); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1622 match idx.entry_as_params(rev) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1623 Some(e) => e, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1624 None => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1625 return Err(PyErr::new::<IndexError, _>( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1626 py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1627 "revlog index out of range", |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1628 )); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1629 } |
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 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
|
1633 .into_object() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1634 } |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1635 _ => self |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1636 ._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
|
1637 .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
|
1638 || 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
|
1639 |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
|
1640 ), |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1641 }) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
1642 } |
51212
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
1643 |
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
|
1644 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
|
1645 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
|
1646 |
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
|
1647 // 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
|
1648 // 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
|
1649 // 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
|
1650 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
|
1651 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
|
1652 .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
|
1653 .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
|
1654 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
|
1655 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
|
1656 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
|
1657 .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
|
1658 .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
|
1659 .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
|
1660 ) |
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 .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
|
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 .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
|
1664 |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1665 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
|
1666 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
|
1667 |
f20c4b307a5a
rust-index: add fast-path for getting a list of all heads as nodes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51258
diff
changeset
|
1668 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
|
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 |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1671 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
|
1672 &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
|
1673 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
|
1674 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
|
1675 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
|
1676 ) -> 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
|
1677 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
|
1678 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
|
1679 None |
3e135e79b7f7
headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51975
diff
changeset
|
1680 } else { |
3e135e79b7f7
headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51975
diff
changeset
|
1681 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
|
1682 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
|
1683 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
|
1684 } else { |
3e135e79b7f7
headrevs: replace a boolean match with a if/else
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51975
diff
changeset
|
1685 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
|
1686 } |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
1687 }; |
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 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
|
1689 (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
|
1690 (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
|
1691 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
|
1692 } |
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 _ => { |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1694 let filtered_revs = |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1695 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
|
1696 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
|
1697 &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
|
1698 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
|
1699 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
|
1700 ) |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1701 } |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1702 }; |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
1703 |
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
|
1704 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
|
1705 // 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
|
1706 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
|
1707 .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
|
1708 .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
|
1709 |
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
|
1710 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
|
1711 .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
|
1712 .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
|
1713 .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
|
1714 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
|
1715 } 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
|
1716 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
|
1717 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
|
1718 { |
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 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
|
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 |
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 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
|
1723 .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
|
1724 .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
|
1725 .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
|
1726 .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
|
1727 .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
|
1728 .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
|
1729 } |
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
|
1730 } |
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
|
1731 |
51394
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1732 fn check_revision( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1733 index: &hg::index::Index, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1734 rev: UncheckedRevision, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1735 py: Python, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1736 ) -> PyResult<Revision> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1737 index |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1738 .check_revision(rev) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1739 .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
|
1740 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1741 |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1742 fn inner_headrevsdiff( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1743 &self, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1744 py: Python, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1745 begin: &PyObject, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1746 end: &PyObject, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1747 ) -> PyResult<PyObject> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1748 let begin = begin.extract::<BaseRevision>(py)?; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1749 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
|
1750 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
|
1751 let begin = |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1752 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
|
1753 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
|
1754 let (removed, added) = index |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1755 .head_revs_diff(begin, end) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1756 .map_err(|e| graph_error(py, e))?; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1757 let removed: Vec<_> = |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1758 removed.into_iter().map(PyRevision::from).collect(); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1759 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
|
1760 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
|
1761 Ok(res) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1762 } |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
1763 |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1764 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
|
1765 &self, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1766 new_heads: &[Revision], |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1767 py: Python<'_>, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1768 ) -> 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
|
1769 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
|
1770 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
|
1771 .iter() |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1772 .map(|r| { |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1773 PyBytes::new( |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1774 py, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1775 index |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1776 .node(*r) |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1777 .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
|
1778 .as_bytes(), |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1779 ) |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1780 .into_object() |
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 .collect(); |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1783 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
|
1784 *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
|
1785 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
|
1786 new_heads_py_list |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1787 } |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1788 |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
1789 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
|
1790 &self, |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
1791 new_heads: &[Revision], |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
1792 py: Python<'_>, |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
1793 ) -> PyList { |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
1794 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
|
1795 .iter() |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51213
diff
changeset
|
1796 .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
|
1797 .collect(); |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
1798 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
|
1799 *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
|
1800 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
|
1801 new_heads_py_list |
51213
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
1802 } |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1803 |
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1804 fn inner_ancestors( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1805 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1806 py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1807 py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1808 ) -> 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
|
1809 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
|
1810 let revs: Vec<_> = rev_pyiter_collect(py, py_revs.as_object(), index)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1811 let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1812 .ancestors(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1813 .map_err(|e| graph_error(py, e))? |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1814 .iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1815 .map(|r| PyRevision::from(*r).into_py_object(py).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1816 .collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1817 Ok(PyList::new(py, &as_vec).into_object()) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1818 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1819 |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1820 fn inner_commonancestorsheads( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1821 &self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1822 py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1823 py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1824 ) -> 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
|
1825 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
|
1826 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
|
1827 let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1828 .common_ancestor_heads(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1829 .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
|
1830 .iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1831 .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
|
1832 .collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1833 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
|
1834 } |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
1835 |
51217
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1836 fn inner_computephasesmapsets( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1837 &self, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1838 py: Python, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1839 py_roots: PyDict, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1840 ) -> 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
|
1841 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
|
1842 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
|
1843 .items_list(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1844 .iter(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1845 .map(|r| { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1846 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
|
1847 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
|
1848 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
|
1849 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
|
1850 .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
|
1851 Ok((phase?, revs)) |
51217
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1852 }) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1853 .collect(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1854 let (len, phase_maps) = index |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1855 .compute_phases_map_sets(roots?) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1856 .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
|
1857 |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1858 // Ugly hack, but temporary |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1859 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
|
1860 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
|
1861 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
|
1862 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
|
1863 // 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
|
1864 // it to `PySet::new`. |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1865 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
|
1866 for rev in roots { |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1867 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
|
1868 } |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1869 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
|
1870 } |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1871 Ok(PyTuple::new( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1872 py, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1873 &[ |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1874 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
|
1875 py_phase_maps.into_object(), |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1876 ], |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1877 ) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1878 .into_object()) |
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 |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1881 fn inner_slicechunktodensity( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1882 &self, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1883 py: Python, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1884 revs: PyObject, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1885 target_density: f64, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1886 min_gap_size: usize, |
51216
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1887 ) -> 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
|
1888 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
|
1889 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
|
1890 let as_nested_vec = |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1891 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
|
1892 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
|
1893 let mut py_chunk = Vec::new(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1894 for chunk in as_nested_vec { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1895 py_chunk.clear(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1896 py_chunk.reserve_exact(chunk.len()); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1897 for rev in chunk { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1898 py_chunk.push( |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1899 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
|
1900 ); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1901 } |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1902 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
|
1903 } |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1904 // 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
|
1905 if res.len() == 1 { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1906 Ok(PyTuple::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1907 } else { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1908 Ok(PyList::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1909 } |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1910 } |
51219
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1911 |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1912 fn inner_reachableroots2( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1913 &self, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1914 py: Python, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1915 min_root: UncheckedRevision, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1916 heads: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1917 roots: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1918 include_path: bool, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1919 ) -> 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
|
1920 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
|
1921 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
|
1922 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
|
1923 })?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1924 let roots: Result<_, _> = roots |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1925 .iter(py)? |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1926 .map(|r| { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1927 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
|
1928 Ok(r) => Ok(UncheckedRevision(r.0)), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1929 Err(e) => Err(e), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1930 }) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1931 }) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1932 .collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1933 let as_set = index |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1934 .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
|
1935 .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
|
1936 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
|
1937 .iter() |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1938 .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
|
1939 .collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1940 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
|
1941 } |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1942 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
|
1943 &self, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1944 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
|
1945 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
|
1946 ) -> 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
|
1947 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
|
1948 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
|
1949 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
|
1950 .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
|
1951 .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
|
1952 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
|
1953 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
|
1954 })?; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1955 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
|
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 } |
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 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
|
1960 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
|
1961 py: Python, |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1962 vfs_base: PyObject, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1963 fncache: PyObject, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1964 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
|
1965 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
|
1966 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
|
1967 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
|
1968 _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
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 _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
|
1974 _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
|
1975 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
|
1976 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
|
1977 ) -> 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
|
1978 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
|
1979 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
|
1980 .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
|
1981 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
|
1982 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
|
1983 .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
|
1984 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
|
1985 .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
|
1986 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
|
1987 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
|
1988 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
|
1989 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
|
1990 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
|
1991 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
|
1992 inline, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1993 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
|
1994 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
|
1995 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
|
1996 ); |
52172
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
1997 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
1998 // 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
|
1999 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
|
2000 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
|
2001 .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
|
2002 |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
2003 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
|
2004 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
|
2005 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
|
2006 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
|
2007 base, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
2008 vfs_is_readonly, |
72bc29f01570
revlog: add glue to use a pure-Rust VFS
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52163
diff
changeset
|
2009 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
|
2010 )), |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2011 index, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2012 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
|
2013 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
|
2014 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
|
2015 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
|
2016 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
|
2017 ); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2018 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
|
2019 py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2020 core, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2021 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
|
2022 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
|
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(buf), |
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(None), |
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), |
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
|
2028 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
|
2029 ) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2030 } |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2031 } |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2032 |
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2033 py_class!(pub class NodeTree |py| { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2034 data nt: RefCell<CoreNodeTree>; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2035 data index: RefCell<UnsafePyLeaked<PySharedIndex>>; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2036 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2037 def __new__(_cls, index: PyObject) -> PyResult<NodeTree> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2038 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
|
2039 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
|
2040 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
|
2041 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2042 |
51248
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
2043 /// 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
|
2044 /// |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
2045 /// 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
|
2046 /// 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
|
2047 /// 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
|
2048 /// (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
|
2049 /// been meanwhile mutated. |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
2050 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
|
2051 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
|
2052 // 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
|
2053 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
|
2054 // 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
|
2055 // - 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
|
2056 // - 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
|
2057 // 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
|
2058 // 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
|
2059 Ok(result.is_err()) |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
2060 } |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
2061 |
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2062 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
|
2063 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
|
2064 // 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
|
2065 let index = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2066 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2067 let rev = UncheckedRevision(rev.0); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2068 let rev = index |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2069 .check_revision(rev) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2070 .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
|
2071 if rev == NULL_REVISION { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2072 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
|
2073 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2074 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2075 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
|
2076 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
|
2077 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
|
2078 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2079 Ok(py.None()) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2080 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2081 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2082 /// 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
|
2083 /// |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2084 /// 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
|
2085 /// 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
|
2086 def prefix_rev_lookup( |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2087 &self, |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2088 node_prefix: PyBytes |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2089 ) -> PyResult<Option<PyRevision>> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2090 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
|
2091 .map_err(|_| PyErr::new::<ValueError, _>( |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2092 py, |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2093 format!("Invalid node or prefix {:?}", |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2094 node_prefix.as_object())) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2095 )?; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2096 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2097 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
|
2098 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
|
2099 // 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
|
2100 let index = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2101 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2102 Ok(nt.find_bin(index, prefix) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2103 .map_err(|e| nodemap_error(py, e))? |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2104 .map(|r| r.into()) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2105 ) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2106 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2107 |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2108 def shortest(&self, node: PyBytes) -> PyResult<usize> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2109 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
|
2110 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
|
2111 // 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
|
2112 let idx = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2113 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
|
2114 { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2115 Ok(Some(l)) => Ok(l), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2116 Ok(None) => Err(revlog_error(py)), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2117 Err(e) => Err(nodemap_error(py, e)), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2118 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2119 } |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2120 }); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2121 |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2122 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
|
2123 unsafe { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2124 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
|
2125 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2126 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
|
2127 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2128 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2129 /// # Safety |
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 /// 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
|
2132 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
|
2133 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
|
2134 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
|
2135 ) -> 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 where |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2137 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
|
2138 { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2139 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
|
2140 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
|
2141 } else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2142 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
|
2143 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2144 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2145 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2146 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
|
2147 py: Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2148 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
|
2149 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
|
2150 ) -> 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
|
2151 where |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2152 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
|
2153 &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
|
2154 ) -> 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
|
2155 { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2156 // 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
|
2157 // 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
|
2158 unsafe { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2159 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
|
2160 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
|
2161 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
|
2162 ); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2163 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
|
2164 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
|
2165 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
|
2166 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
|
2167 // 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
|
2168 // 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
|
2169 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
|
2170 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2171 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2172 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2173 /// 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
|
2174 /// 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
|
2175 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
|
2176 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
|
2177 _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
|
2178 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
|
2179 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
|
2180 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
|
2181 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2182 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2183 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
|
2184 /// # Safety |
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 /// `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
|
2187 /// 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
|
2188 #[inline] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2189 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
|
2190 Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2191 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
|
2192 _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
|
2193 len, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2194 current_len: 0, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2195 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
|
2196 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2197 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2198 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2199 /// 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
|
2200 /// 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
|
2201 /// written. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2202 #[inline] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2203 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
|
2204 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
|
2205 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2206 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2207 |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2208 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
|
2209 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
|
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 #[inline] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2212 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
|
2213 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
|
2214 unsafe { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2215 // 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
|
2216 // 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
|
2217 // [`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
|
2218 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
|
2219 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
|
2220 } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2221 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
|
2222 } |
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 #[inline] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
52158
diff
changeset
|
2225 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
|
2226 // 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
|
2227 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
|
2228 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
|
2229 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
|
2230 "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
|
2231 ); |
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.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
|
2233 } |
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 |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2236 fn revlog_error(py: Python) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2237 match py |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2238 .import("mercurial.error") |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2239 .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
|
2240 { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2241 Err(e) => e, |
47305
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
2242 Ok(cls) => PyErr::from_instance( |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
2243 py, |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
2244 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
|
2245 ), |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2246 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2247 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2248 |
51212
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
2249 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
|
2250 // ParentOutOfRange is currently the only alternative |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
2251 // 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
|
2252 PyErr::new::<ValueError, _>(py, "parent out of range") |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
2253 } |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
2254 |
51196
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51195
diff
changeset
|
2255 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
|
2256 PyErr::new::<ValueError, _>( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2257 py, |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2258 format!( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2259 "Inconsistency: Revision {} found in nodemap \ |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2260 is not in revlog index", |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2261 rev |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2262 ), |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2263 ) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2264 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2265 |
51197
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
2266 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
|
2267 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
|
2268 py, |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
2269 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
|
2270 ) |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
2271 } |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
2272 |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2273 /// Standard treatment of NodeMapError |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2274 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
|
2275 match err { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2276 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
|
2277 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
|
2278 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2279 } |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
2280 |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2281 /// 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
|
2282 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
|
2283 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
|
2284 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
|
2285 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
|
2286 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
|
2287 |
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
2288 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
|
2289 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
|
2290 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2291 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
|
2292 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
|
2293 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
|
2294 |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2295 Ok(m) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
2296 } |