author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Fri, 27 Sep 2024 03:55:40 +0200 | |
changeset 51975 | 609700e5d8df |
parent 51967 | 69bfd6b242ed |
child 51976 | 3e135e79b7f7 |
permissions | -rw-r--r-- |
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. |
f98f0e3ddaa1
rust-index: add a function to convert PyObject index for hg-core
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
|
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
|
8 |
use crate::{ |
51219
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
9 |
conversion::{rev_pyiter_collect, rev_pyiter_collect_or_else}, |
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
|
10 |
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
|
11 |
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
|
12 |
}; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
13 |
use cpython::{ |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
14 |
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
|
15 |
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
|
16 |
ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyInt, PyList, |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
17 |
PyModule, PyObject, PyResult, PySet, PyString, PyTuple, Python, |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
18 |
PythonObject, ToPyObject, UnsafePyLeaked, |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
19 |
}; |
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
|
20 |
use hg::{ |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
21 |
errors::HgError, |
51226
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
22 |
index::{ |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
23 |
IndexHeader, Phase, RevisionDataParams, SnapshotsCache, |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
24 |
INDEX_ENTRY_SIZE, |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
25 |
}, |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
26 |
nodemap::{Block, NodeMapError, NodeTree as CoreNodeTree}, |
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
|
27 |
revlog::{nodemap::NodeMap, Graph, NodePrefix, RevlogError, RevlogIndex}, |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
28 |
BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION, |
44507
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
29 |
}; |
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
|
30 |
use std::{ |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
31 |
cell::RefCell, |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
32 |
collections::{HashMap, HashSet}, |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
33 |
}; |
51236
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
34 |
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
|
35 |
|
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
|
36 |
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
|
37 |
/// 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
|
38 |
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
|
39 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
40 |
|
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
41 |
/// 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
|
42 |
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
|
43 |
py: Python, |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
44 |
index: PyObject, |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
45 |
) -> PyResult<UnsafePyLeaked<PySharedIndex>> { |
51251
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
46 |
let midx = index.extract::<Index>(py)?; |
51236
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
47 |
let leaked = midx.index(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
|
48 |
// Safety: we don't leak the "faked" reference out of the `UnsafePyLeaked` |
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 |
Ok(unsafe { leaked.map(py, |idx| PySharedIndex { inner: idx }) }) |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
50 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
51 |
|
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
56 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
57 |
|
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 |
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
|
59 |
#[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
|
60 |
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
|
61 |
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
|
62 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
63 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
64 |
|
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
65 |
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
|
66 |
#[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
|
67 |
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
|
68 |
&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
|
69 |
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
|
70 |
) -> 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
|
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 |
// 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
|
73 |
// 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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
} |
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 |
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
|
79 |
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
|
80 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
81 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
82 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
83 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
84 |
|
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 |
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
|
86 |
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
|
87 |
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
|
88 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
92 |
} |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
93 |
|
51251
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
94 |
py_class!(pub class Index |py| { |
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
|
95 |
@shared data index: hg::index::Index; |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
96 |
data nt: RefCell<Option<CoreNodeTree>>; |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
97 |
data docket: RefCell<Option<PyObject>>; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
98 |
// Holds a reference to the mmap'ed persistent nodemap data |
51183
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
99 |
data nodemap_mmap: RefCell<Option<PyBuffer>>; |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
100 |
// Holds a reference to the mmap'ed persistent index data |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
101 |
data index_mmap: RefCell<Option<PyBuffer>>; |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
102 |
data head_revs_py_list: RefCell<Option<PyList>>; |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
103 |
data head_node_ids_py_list: RefCell<Option<PyList>>; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
104 |
|
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
105 |
def __new__( |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
106 |
_cls, |
51188
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
107 |
data: PyObject, |
13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51187
diff
changeset
|
108 |
default_header: u32, |
51251
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
109 |
) -> PyResult<Self> { |
51250
96e05f1a99bd
rust-index: stop instantiating a C Index
Georges Racinet <georges.racinet@octobus.net>
parents:
51248
diff
changeset
|
110 |
Self::new(py, data, default_header) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
111 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
112 |
|
44012
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
113 |
/// Compatibility layer used for Python consumers needing access to the C index |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
114 |
/// |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
115 |
/// Only use case so far is `scmutil.shortesthexnodeidprefix`, |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
116 |
/// that may need to build a custom `nodetree`, based on a specified revset. |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
117 |
/// With a Rust implementation of the nodemap, we will be able to get rid of |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
118 |
/// this, by exposing our own standalone nodemap class, |
51250
96e05f1a99bd
rust-index: stop instantiating a C Index
Georges Racinet <georges.racinet@octobus.net>
parents:
51248
diff
changeset
|
119 |
/// ready to accept `Index`. |
96e05f1a99bd
rust-index: stop instantiating a C Index
Georges Racinet <georges.racinet@octobus.net>
parents:
51248
diff
changeset
|
120 |
/* def get_cindex(&self) -> PyResult<PyObject> { |
44012
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
121 |
Ok(self.cindex(py).borrow().inner().clone_ref(py)) |
443dc1655923
rust-index: expose a method to retrieve the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
44011
diff
changeset
|
122 |
} |
51250
96e05f1a99bd
rust-index: stop instantiating a C Index
Georges Racinet <georges.racinet@octobus.net>
parents:
51248
diff
changeset
|
123 |
*/ |
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
|
124 |
// Index API involving nodemap, as defined in mercurial/pure/parsers.py |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
125 |
|
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
|
126 |
/// Return Revision if found, raises a bare `error.RevlogError` |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
127 |
/// in case of ambiguity, same as C version does |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
128 |
def get_rev(&self, node: PyBytes) -> PyResult<Option<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
|
129 |
let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
130 |
let nt = opt.as_ref().unwrap(); |
51193
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
131 |
let ridx = &*self.index(py).borrow(); |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
132 |
let node = node_from_py_bytes(py, &node)?; |
51193
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
133 |
let rust_rev = |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
134 |
nt.find_bin(ridx, node.into()).map_err(|e| nodemap_error(py, e))?; |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
135 |
Ok(rust_rev.map(Into::into)) |
f95f70cf2ee2
rust-index: check rindex and cindex return the same get_rev
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51192
diff
changeset
|
136 |
|
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
|
137 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
138 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
139 |
/// same as `get_rev()` but raises a bare `error.RevlogError` if node |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
140 |
/// is not found. |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
141 |
/// |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
142 |
/// No need to repeat `node` in the exception, `mercurial/revlog.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
|
143 |
/// will catch and rewrap with it |
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
144 |
def rev(&self, node: PyBytes) -> PyResult<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
|
145 |
self.get_rev(py, node)?.ok_or_else(|| revlog_error(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
|
146 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
147 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
148 |
/// return True if the node exist in the index |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
149 |
def has_node(&self, node: PyBytes) -> PyResult<bool> { |
51201
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
150 |
// TODO OPTIM we could avoid a needless conversion here, |
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
151 |
// to do when scaffolding for pure Rust switch is removed, |
297fa956b6c4
rust-index: optim note for post-scaffolding removal
Georges Racinet <georges.racinet@octobus.net>
parents:
51200
diff
changeset
|
152 |
// as `get_rev()` currently does the necessary assertions |
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
|
153 |
self.get_rev(py, node).map(|opt| opt.is_some()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
154 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
155 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
156 |
/// find length of shortest hex nodeid of a binary ID |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
157 |
def shortest(&self, node: PyBytes) -> PyResult<usize> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
158 |
let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
159 |
let nt = opt.as_ref().unwrap(); |
51205
274abd1562a2
rust-index: use the rust index in `shortest`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51204
diff
changeset
|
160 |
let idx = &*self.index(py).borrow(); |
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
|
161 |
match nt.unique_prefix_len_node(idx, &node_from_py_bytes(py, &node)?) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
162 |
{ |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
163 |
Ok(Some(l)) => Ok(l), |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
164 |
Ok(None) => Err(revlog_error(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
|
165 |
Err(e) => Err(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
|
166 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
167 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
168 |
|
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
169 |
def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> { |
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
|
170 |
let opt = self.get_nodetree(py)?.borrow(); |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
171 |
let nt = opt.as_ref().unwrap(); |
51207
72d16685d63a
rust-index: use the Rust index in `partialmatch`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51205
diff
changeset
|
172 |
let idx = &*self.index(py).borrow(); |
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
|
173 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
174 |
let node_as_string = if cfg!(feature = "python3-sys") { |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
175 |
node.cast_as::<PyString>(py)?.to_string(py)?.to_string() |
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
|
176 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
177 |
else { |
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
178 |
let node = node.extract::<PyBytes>(py)?; |
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
|
179 |
String::from_utf8_lossy(node.data(py)).to_string() |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
180 |
}; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
181 |
|
49374
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
182 |
let prefix = NodePrefix::from_hex(&node_as_string) |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
183 |
.map_err(|_| PyErr::new::<ValueError, _>( |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
184 |
py, format!("Invalid node or prefix '{}'", node_as_string)) |
455fce57e89e
rust: don't swallow valuable error information
Rapha?l Gom?s <rgomes@octobus.net>
parents:
48269
diff
changeset
|
185 |
)?; |
46432
18a261b11b20
rust: Remove hex parsing from the nodemap
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
186 |
|
48269
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
187 |
nt.find_bin(idx, prefix) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
188 |
// TODO make an inner API returning the node directly |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
189 |
.map(|opt| opt.map( |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
190 |
|rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
191 |
.map_err(|e| nodemap_error(py, e)) |
aa88fb60ecb4
rust-nodemap: backed out mitigation for issue 6554
Georges Racinet <georges.racinet@octobus.net>
parents:
47799
diff
changeset
|
192 |
|
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
|
193 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
194 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
195 |
/// append an index entry |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
196 |
def append(&self, tup: PyTuple) -> PyResult<PyObject> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
197 |
if tup.len(py) < 8 { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
198 |
// this is better than the panic promised by tup.get_item() |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
199 |
return Err( |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
200 |
PyErr::new::<IndexError, _>(py, "tuple index out of range")) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
201 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
202 |
let node_bytes = tup.get_item(py, 7).extract(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
|
203 |
let node = node_from_py_object(py, &node_bytes)?; |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
204 |
|
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
205 |
let rev = self.len(py)? 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
|
206 |
|
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
207 |
// This is ok since we will just add the revision to the index |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
208 |
let rev = Revision(rev); |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
209 |
self.index(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
210 |
.borrow_mut() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
211 |
.append(py_tuple_to_revision_data_params(py, tup)?) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
212 |
.unwrap(); |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
213 |
let idx = &*self.index(py).borrow(); |
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
|
214 |
self.get_nodetree(py)?.borrow_mut().as_mut().unwrap() |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
215 |
.insert(idx, &node, 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
|
216 |
.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
|
217 |
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
|
218 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
219 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
220 |
def __delitem__(&self, key: PyObject) -> PyResult<()> { |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
221 |
// __delitem__ is both for `del idx[r]` and `del idx[r1:r2]` |
51247
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
222 |
let start = if let Ok(rev) = key.extract(py) { |
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
223 |
UncheckedRevision(rev) |
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
224 |
} else { |
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
225 |
let start = key.getattr(py, "start")?; |
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
226 |
UncheckedRevision(start.extract(py)?) |
a8ca22119385
rust-index: add support for `del index[r]`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51246
diff
changeset
|
227 |
}; |
51192
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
228 |
let start = self.index(py) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
229 |
.borrow() |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
230 |
.check_revision(start) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
231 |
.ok_or_else(|| { |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
232 |
nodemap_error(py, NodeMapError::RevisionNotInIndex(start)) |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
233 |
})?; |
f6403bcd9f96
rust-index: synchronize remove to Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51191
diff
changeset
|
234 |
self.index(py).borrow_mut().remove(start).unwrap(); |
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
|
235 |
let mut opt = self.get_nodetree(py)?.borrow_mut(); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49374
diff
changeset
|
236 |
let nt = opt.as_mut().unwrap(); |
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
|
237 |
nt.invalidate_all(); |
49914
58074252db3c
rust: run `cargo clippy`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49374
diff
changeset
|
238 |
self.fill_nodemap(py, nt)?; |
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
|
239 |
Ok(()) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
240 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
241 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
242 |
// |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
243 |
// Index methods previously reforwarded to C index (tp_methods) |
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
244 |
// Same ordering as in revlog.c |
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
|
245 |
// |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
246 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
247 |
/// return the gca set of the given revs |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
248 |
def ancestors(&self, *args, **_kw) -> PyResult<PyObject> { |
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
249 |
let rust_res = self.inner_ancestors(py, args)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
250 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
251 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
252 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
253 |
/// return the heads of the common ancestors of the given revs |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
254 |
def commonancestorsheads(&self, *args, **_kw) -> PyResult<PyObject> { |
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
255 |
let rust_res = self.inner_commonancestorsheads(py, args)?; |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
256 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
257 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
258 |
|
44511
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
259 |
/// Clear the index caches and inner py_class data. |
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
260 |
/// It is Python's responsibility to call `update_nodemap_data` again. |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
261 |
def clearcaches(&self) -> PyResult<PyObject> { |
44511
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
262 |
self.nt(py).borrow_mut().take(); |
cadcc8c20860
rust-nodemap: also clear Rust data in `clearcaches`
Georges Racinet <georges.racinet@octobus.net>
parents:
44510
diff
changeset
|
263 |
self.docket(py).borrow_mut().take(); |
51183
8ade5e6cdb61
rust-mixed-index: rename variable to make the next change clearer
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51117
diff
changeset
|
264 |
self.nodemap_mmap(py).borrow_mut().take(); |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
265 |
self.head_revs_py_list(py).borrow_mut().take(); |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
266 |
self.head_node_ids_py_list(py).borrow_mut().take(); |
51231
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51230
diff
changeset
|
267 |
self.index(py).borrow().clear_caches(); |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
268 |
Ok(py.None()) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
269 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
270 |
|
47034
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
271 |
/// return the raw binary string representing a revision |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
272 |
def entry_binary(&self, *args, **_kw) -> PyResult<PyObject> { |
51200
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
273 |
let rindex = self.index(py).borrow(); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
274 |
let rev = UncheckedRevision(args.get_item(py, 0).extract(py)?); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
275 |
let rust_bytes = rindex.check_revision(rev).and_then( |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
276 |
|r| rindex.entry_binary(r)) |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
277 |
.ok_or_else(|| rev_not_in_index(py, rev))?; |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
278 |
let rust_res = PyBytes::new(py, rust_bytes).into_object(); |
7434747343ab
rust-index: check that the entry bytes are the same in both indexes
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51199
diff
changeset
|
279 |
Ok(rust_res) |
47034
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
280 |
} |
0d8ff1f4ab0c
revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46974
diff
changeset
|
281 |
|
47037
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
282 |
/// return a binary packed version of the header |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
283 |
def pack_header(&self, *args, **_kw) -> PyResult<PyObject> { |
51195
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51194
diff
changeset
|
284 |
let rindex = self.index(py).borrow(); |
51cc12158f97
rust-index: add `pack_header` support
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51194
diff
changeset
|
285 |
let packed = rindex.pack_header(args.get_item(py, 0).extract(py)?); |
51199
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
286 |
let rust_res = PyBytes::new(py, &packed).into_object(); |
16d477bb0078
rust-index: return variables systematic naming convention
Georges Racinet <georges.racinet@octobus.net>
parents:
51198
diff
changeset
|
287 |
Ok(rust_res) |
47037
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
288 |
} |
d57386e5c80e
revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47034
diff
changeset
|
289 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
290 |
/// compute phases |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
291 |
def computephasesmapsets(&self, *args, **_kw) -> PyResult<PyObject> { |
51217
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
292 |
let py_roots = args.get_item(py, 0).extract::<PyDict>(py)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
293 |
let rust_res = self.inner_computephasesmapsets(py, py_roots)?; |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
294 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
295 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
296 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
297 |
/// reachableroots |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
298 |
def reachableroots2(&self, *args, **_kw) -> PyResult<PyObject> { |
51219
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
299 |
let rust_res = self.inner_reachableroots2( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
300 |
py, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
301 |
UncheckedRevision(args.get_item(py, 0).extract(py)?), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
302 |
args.get_item(py, 1), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
303 |
args.get_item(py, 2), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
304 |
args.get_item(py, 3).extract(py)?, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
305 |
)?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
306 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
307 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
308 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
309 |
/// get head revisions |
51962
fb4d49c52c06
rust-cpython: also accept the `filteredrevs` argument in index.headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51464
diff
changeset
|
310 |
def headrevs(&self, *args, **_kw) -> PyResult<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
|
311 |
let (filtered_revs, stop_rev) = match &args.len(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
|
312 |
0 => Ok((py.None(), py.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
|
313 |
1 => Ok((args.get_item(py, 0), py.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
|
314 |
2 => Ok((args.get_item(py, 0), args.get_item(py, 1))), |
51962
fb4d49c52c06
rust-cpython: also accept the `filteredrevs` argument in index.headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51464
diff
changeset
|
315 |
_ => Err(PyErr::new::<cpython::exc::TypeError, _>(py, "too many arguments")), |
fb4d49c52c06
rust-cpython: also accept the `filteredrevs` argument in index.headrevs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51464
diff
changeset
|
316 |
}?; |
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
|
317 |
self.inner_headrevs(py, &filtered_revs, &stop_rev) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
318 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
319 |
|
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
|
320 |
/// get head nodeids |
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
|
321 |
def head_node_ids(&self) -> PyResult<PyObject> { |
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
|
322 |
let rust_res = self.inner_head_node_ids(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
|
323 |
Ok(rust_res) |
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
|
324 |
} |
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
|
325 |
|
51394
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
326 |
/// get diff in head revisions |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
327 |
def headrevsdiff(&self, *args, **_kw) -> PyResult<PyObject> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
328 |
let rust_res = self.inner_headrevsdiff( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
329 |
py, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
330 |
&args.get_item(py, 0), |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
331 |
&args.get_item(py, 1))?; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
332 |
Ok(rust_res) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
333 |
} |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
334 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
335 |
/// True if the object is a snapshot |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
336 |
def issnapshot(&self, *args, **_kw) -> PyResult<bool> { |
51208
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
337 |
let index = self.index(py).borrow(); |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
338 |
let result = index |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
339 |
.is_snapshot(UncheckedRevision(args.get_item(py, 0).extract(py)?)) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
340 |
.map_err(|e| { |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
341 |
PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
342 |
})?; |
b8c89957a6b7
rust-index: add `is_snapshot` method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51207
diff
changeset
|
343 |
Ok(result) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
344 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
345 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
346 |
/// Gather snapshot data in a cache dict |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
347 |
def findsnapshots(&self, *args, **_kw) -> PyResult<PyObject> { |
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
348 |
let index = self.index(py).borrow(); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
349 |
let cache: PyDict = args.get_item(py, 0).extract(py)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
350 |
// this methods operates by setting new values in the cache, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
351 |
// hence we will compare results by letting the C implementation |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
352 |
// operate over a deepcopy of the cache, and finally compare both |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
353 |
// caches. |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
354 |
let c_cache = PyDict::new(py); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
355 |
for (k, v) in cache.items(py) { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
356 |
c_cache.set_item(py, k, PySet::new(py, v)?)?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
357 |
} |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
358 |
|
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
359 |
let start_rev = UncheckedRevision(args.get_item(py, 1).extract(py)?); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
360 |
let end_rev = UncheckedRevision(args.get_item(py, 2).extract(py)?); |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
361 |
let mut cache_wrapper = PySnapshotsCache{ py, dict: cache }; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
362 |
index.find_snapshots( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
363 |
start_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
364 |
end_rev, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
365 |
&mut cache_wrapper, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
366 |
).map_err(|_| revlog_error(py))?; |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
367 |
Ok(py.None()) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
368 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
369 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
370 |
/// determine revisions with deltas to reconstruct fulltext |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
371 |
def deltachain(&self, *args, **_kw) -> PyResult<PyObject> { |
51210
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
372 |
let index = self.index(py).borrow(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
373 |
let rev = args.get_item(py, 0).extract::<BaseRevision>(py)?.into(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
374 |
let stop_rev = |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
375 |
args.get_item(py, 1).extract::<Option<BaseRevision>>(py)?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
376 |
let rev = index.check_revision(rev).ok_or_else(|| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
377 |
nodemap_error(py, NodeMapError::RevisionNotInIndex(rev)) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
378 |
})?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
379 |
let stop_rev = if let Some(stop_rev) = stop_rev { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
380 |
let stop_rev = UncheckedRevision(stop_rev); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
381 |
Some(index.check_revision(stop_rev).ok_or_else(|| { |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
382 |
nodemap_error(py, NodeMapError::RevisionNotInIndex(stop_rev)) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
383 |
})?) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
384 |
} else {None}; |
51232
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
385 |
let using_general_delta = args.get_item(py, 2) |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
386 |
.extract::<Option<u32>>(py)? |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
387 |
.map(|i| i != 0); |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
388 |
let (chain, stopped) = index.delta_chain( |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
389 |
rev, stop_rev, using_general_delta |
456e0fe702e8
rust-index: honour incoming using_general_delta in `deltachain`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51231
diff
changeset
|
390 |
).map_err(|e| { |
51210
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
391 |
PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string()) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
392 |
})?; |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
393 |
|
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
394 |
let chain: Vec<_> = chain.into_iter().map(|r| r.0).collect(); |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
395 |
Ok( |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
396 |
PyTuple::new( |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
397 |
py, |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
398 |
&[ |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
399 |
chain.into_py_object(py).into_object(), |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
400 |
stopped.into_py_object(py).into_object() |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
401 |
] |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
402 |
).into_object() |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
403 |
) |
62e39bef36ca
rust-index: add support for delta-chain computation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51209
diff
changeset
|
404 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
405 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
406 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
407 |
/// slice planned chunk read to reach a density threshold |
51243
41e19e8a6133
rust-index: stop using C index
Georges Racinet <georges.racinet@octobus.net>
parents:
51242
diff
changeset
|
408 |
def slicechunktodensity(&self, *args, **_kw) -> PyResult<PyObject> { |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
409 |
let rust_res = self.inner_slicechunktodensity( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
410 |
py, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
411 |
args.get_item(py, 0), |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
412 |
args.get_item(py, 1).extract(py)?, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
413 |
args.get_item(py, 2).extract(py)? |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
414 |
)?; |
51216
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
415 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
416 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
417 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
418 |
// index_sequence_methods and index_mapping_methods. |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
419 |
// |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
420 |
// Since we call back through the high level Python API, |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
421 |
// there's no point making a distinction between index_get |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
422 |
// and index_getitem. |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
423 |
// gracinet 2023: this above is no longer true for the pure Rust impl |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
424 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
425 |
def __len__(&self) -> PyResult<usize> { |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
426 |
self.len(py) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
427 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
428 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
429 |
def __getitem__(&self, key: PyObject) -> PyResult<PyObject> { |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
430 |
let rust_res = self.inner_getitem(py, key.clone_ref(py))?; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
431 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
432 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
433 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
434 |
def __contains__(&self, item: PyObject) -> PyResult<bool> { |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
435 |
// ObjectProtocol does not seem to provide contains(), so |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
436 |
// this is an equivalent implementation of the index_contains() |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
437 |
// defined in revlog.c |
50974
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49914
diff
changeset
|
438 |
match item.extract::<i32>(py) { |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
439 |
Ok(rev) => { |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
440 |
Ok(rev >= -1 && rev < self.len(py)? as BaseRevision) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
441 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
442 |
Err(_) => { |
51204
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
443 |
let item_bytes: PyBytes = item.extract(py)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
444 |
let rust_res = self.has_node(py, item_bytes)?; |
b67cd0d0e976
rust-index: add checks that `__contains__` is synchronized
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51203
diff
changeset
|
445 |
Ok(rust_res) |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
446 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
447 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
448 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
449 |
|
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
450 |
def nodemap_data_all(&self) -> PyResult<PyBytes> { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
451 |
self.inner_nodemap_data_all(py) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
452 |
} |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
453 |
|
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
454 |
def nodemap_data_incremental(&self) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
455 |
self.inner_nodemap_data_incremental(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
456 |
} |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
457 |
def update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
458 |
&self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
459 |
docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
460 |
nm_data: PyObject |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
461 |
) -> PyResult<PyObject> { |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
462 |
self.inner_update_nodemap_data(py, docket, nm_data) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
463 |
} |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
464 |
|
46974
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46432
diff
changeset
|
465 |
@property |
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46432
diff
changeset
|
466 |
def entry_size(&self) -> PyResult<PyInt> { |
51226
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
467 |
let rust_res: PyInt = INDEX_ENTRY_SIZE.to_py_object(py); |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
468 |
Ok(rust_res) |
46974
3c9208702db3
revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46432
diff
changeset
|
469 |
} |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
470 |
|
47268
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
471 |
@property |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
472 |
def rust_ext_compat(&self) -> PyResult<PyInt> { |
51226
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
473 |
// will be entirely removed when the Rust index yet useful to |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
474 |
// implement in Rust to detangle things when removing `self.cindex` |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
475 |
let rust_res: PyInt = 1.to_py_object(py); |
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
476 |
Ok(rust_res) |
47268
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
477 |
} |
9d1a8829f959
revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47037
diff
changeset
|
478 |
|
51245
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
479 |
@property |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
480 |
def is_rust(&self) -> PyResult<PyBool> { |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
481 |
Ok(false.to_py_object(py)) |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
482 |
} |
8b243e2a3bc4
rust-index: a property to identify the Rust index as such
Georges Racinet <georges.racinet@octobus.net>
parents:
51244
diff
changeset
|
483 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
484 |
}); |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
485 |
|
51184
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
486 |
/// 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
|
487 |
/// 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
|
488 |
/// 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
|
489 |
/// 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
|
490 |
/// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
491 |
/// # Safety |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
492 |
/// |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
493 |
/// 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
|
494 |
/// 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
|
495 |
#[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
|
496 |
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
|
497 |
py: Python, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
498 |
data: PyObject, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
499 |
) -> PyResult<( |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
)> { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
|
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
506 |
// 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
|
507 |
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
|
508 |
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
|
509 |
&& 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
|
510 |
&& 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
|
511 |
{ |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
512 |
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
|
513 |
} else { |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
514 |
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
|
515 |
py, |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
516 |
"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
|
517 |
.to_string(), |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
518 |
)); |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
519 |
}; |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
520 |
|
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
521 |
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
|
522 |
} |
8c4e8d06432e
rust-mixed-index: move the mmap keepalive into a function
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51183
diff
changeset
|
523 |
|
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
524 |
fn py_tuple_to_revision_data_params( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
525 |
py: Python, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
526 |
tuple: PyTuple, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
527 |
) -> PyResult<RevisionDataParams> { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
528 |
if tuple.len(py) < 8 { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
529 |
// 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
|
530 |
return Err(PyErr::new::<IndexError, _>( |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
531 |
py, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
532 |
"tuple index out of range", |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
533 |
)); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
534 |
} |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
535 |
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
|
536 |
let node_id = tuple |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
537 |
.get_item(py, 7) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
538 |
.extract::<PyBytes>(py)? |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
539 |
.data(py) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
540 |
.try_into() |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
541 |
.unwrap(); |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
542 |
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
|
543 |
let data_offset = offset_or_flags >> 16; |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
544 |
Ok(RevisionDataParams { |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
545 |
flags, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
546 |
data_offset, |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
547 |
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
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
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
|
553 |
node_id, |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
554 |
..Default::default() |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
555 |
}) |
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
556 |
} |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
557 |
fn revision_data_params_to_py_tuple( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
558 |
py: Python, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
559 |
params: RevisionDataParams, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
560 |
) -> PyTuple { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
561 |
PyTuple::new( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
562 |
py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
563 |
&[ |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
564 |
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
|
565 |
params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
566 |
.data_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
567 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
568 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
569 |
params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
570 |
.data_uncompressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
571 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
572 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
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
|
577 |
PyBytes::new(py, ¶ms.node_id) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
578 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
579 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
580 |
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
|
581 |
params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
582 |
._sidedata_compressed_length |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
583 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
584 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
585 |
params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
586 |
.data_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
587 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
588 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
589 |
params |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
590 |
._sidedata_compression_mode |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
591 |
.into_py_object(py) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
592 |
.into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
593 |
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
|
594 |
], |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
595 |
) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
596 |
} |
51189
65c9032e2e5a
rust-index: synchronize append method
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51188
diff
changeset
|
597 |
|
51209
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
598 |
struct PySnapshotsCache<'p> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
599 |
py: Python<'p>, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
600 |
dict: PyDict, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
601 |
} |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
602 |
|
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
603 |
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
|
604 |
fn insert_for( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
605 |
&mut self, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
606 |
rev: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
607 |
value: BaseRevision, |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
608 |
) -> Result<(), RevlogError> { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
609 |
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
|
610 |
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
|
611 |
Some(obj) => obj |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
612 |
.extract::<PySet>(self.py) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
613 |
.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
|
614 |
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
|
615 |
.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
|
616 |
} |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
617 |
.map_err(|_| { |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
618 |
RevlogError::Other(HgError::unsupported( |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
619 |
"Error in Python caches handling", |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
620 |
)) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
621 |
}) |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
622 |
} |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
623 |
} |
9b06e7f32bc5
rust-index: add support for `find_snapshots`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51208
diff
changeset
|
624 |
|
51251
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
625 |
impl Index { |
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
626 |
fn new(py: Python, data: PyObject, header: u32) -> PyResult<Self> { |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
627 |
// Safety: we keep the buffer around inside the class as `index_mmap` |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
628 |
let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; |
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
629 |
|
44503
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
630 |
Self::create_instance( |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
631 |
py, |
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
|
632 |
hg::index::Index::new( |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
633 |
bytes, |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
634 |
IndexHeader::parse(&header.to_be_bytes()) |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
635 |
.expect("default header is broken") |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
636 |
.unwrap(), |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
637 |
) |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
638 |
.map_err(|e| { |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
639 |
revlog_error_with_msg(py, e.to_string().as_bytes()) |
7eea2e4109ae
rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents:
51232
diff
changeset
|
640 |
})?, |
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
|
641 |
RefCell::new(None), |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
642 |
RefCell::new(None), |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
643 |
RefCell::new(None), |
51187
6ec8387eb0be
rust-index: pass data down to the Rust index
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51184
diff
changeset
|
644 |
RefCell::new(Some(buf)), |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
645 |
RefCell::new(None), |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
646 |
RefCell::new(None), |
44503
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
647 |
) |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
648 |
} |
887d0f921b34
rust-index: moved constructor in separate impl block
Georges Racinet <georges.racinet@octobus.net>
parents:
44070
diff
changeset
|
649 |
|
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
650 |
fn len(&self, py: Python) -> PyResult<usize> { |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
651 |
let rust_index_len = self.index(py).borrow().len(); |
51226
1b23aaf5eb7b
rust-index: optimize find_gca_candidates() on less than 8 revisions
Georges Racinet <georges.racinet@octobus.net>
parents:
51222
diff
changeset
|
652 |
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
|
653 |
} |
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
654 |
|
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
|
655 |
/// 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
|
656 |
/// 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
|
657 |
/// 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
|
658 |
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
|
659 |
&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
|
660 |
py: Python, |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
661 |
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
|
662 |
) -> PyResult<PyObject> { |
51203
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51202
diff
changeset
|
663 |
let index = self.index(py).borrow(); |
51190
e79b0a4be3a7
rust-index: check equality between rust and cindex for `__len__`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51189
diff
changeset
|
664 |
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
|
665 |
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
|
666 |
// in this case node() won't ever return 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
|
667 |
nt.insert(&*index, index.node(rev).unwrap(), rev) |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
668 |
.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
|
669 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
670 |
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
|
671 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
672 |
|
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
673 |
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
|
674 |
&'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
|
675 |
py: Python<'a>, |
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
676 |
) -> 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
|
677 |
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
|
678 |
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
|
679 |
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
|
680 |
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
|
681 |
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
|
682 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
683 |
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
|
684 |
} |
857cc79247ac
rust-nodemap: use proper Index API instead of using the C API
Rapha?l Gom?s <rgomes@octobus.net>
parents:
44506
diff
changeset
|
685 |
|
44508
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
686 |
/// 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
|
687 |
fn inner_nodemap_data_all(&self, py: Python) -> PyResult<PyBytes> { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
688 |
let nodemap = self.get_nodetree(py)?.borrow_mut().take().unwrap(); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
689 |
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
|
690 |
|
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
691 |
// 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
|
692 |
// scratch |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
693 |
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
|
694 |
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
|
695 |
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
|
696 |
|
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
697 |
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
|
698 |
assert_eq!(readonly.len(), 0); |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
699 |
|
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
700 |
bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
701 |
} else { |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
702 |
bytes |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
703 |
}; |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
704 |
|
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
705 |
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
|
706 |
Ok(bytes) |
b581231ae9d1
rust-nodemap: add binding for `nodemap_data_all`
Georges Racinet <georges.racinet@octobus.net>
parents:
44507
diff
changeset
|
707 |
} |
44509
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
708 |
|
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
709 |
/// 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
|
710 |
/// (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
|
711 |
fn inner_nodemap_data_incremental( |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
712 |
&self, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
713 |
py: Python, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
714 |
) -> PyResult<PyObject> { |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
715 |
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
|
716 |
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
|
717 |
Some(d) => d, |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
718 |
None => return Ok(py.None()), |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
719 |
}; |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
720 |
|
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
721 |
let node_tree = self.get_nodetree(py)?.borrow_mut().take().unwrap(); |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
|
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
726 |
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
|
727 |
.to_py_object(py) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
728 |
.into_object()) |
5bbf887275b0
rust-nodemap: add binding for `nodemap_data_incremental`
Georges Racinet <georges.racinet@octobus.net>
parents:
44508
diff
changeset
|
729 |
} |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
730 |
|
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
731 |
/// 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
|
732 |
/// 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
|
733 |
fn inner_update_nodemap_data( |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
734 |
&self, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
735 |
py: Python, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
736 |
docket: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
737 |
nm_data: PyObject, |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
738 |
) -> 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
|
739 |
// 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
|
740 |
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
|
741 |
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
|
742 |
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
|
743 |
|
51244
8dbd985733ff
rust-cpython-revlog: renamed NodeTree import as CoreNodeTree
Georges Racinet <georges.racinet@octobus.net>
parents:
51243
diff
changeset
|
744 |
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
|
745 |
|
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
746 |
let data_tip = docket |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
747 |
.getattr(py, "tip_rev")? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
748 |
.extract::<BaseRevision>(py)? |
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
749 |
.into(); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
750 |
self.docket(py).borrow_mut().replace(docket.clone_ref(py)); |
51203
952e3cd7568f
rust-index: using the Rust index in nodemap updating methods
Georges Racinet <georges.racinet@octobus.net>
parents:
51202
diff
changeset
|
751 |
let idx = self.index(py).borrow(); |
50974
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49914
diff
changeset
|
752 |
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
|
753 |
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
|
754 |
})?; |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
755 |
let current_tip = idx.len(); |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
756 |
|
50976
4c5f6e95df84
rust: make `Revision` a newtype
Rapha?l Gom?s <rgomes@octobus.net>
parents:
50974
diff
changeset
|
757 |
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
|
758 |
let rev = Revision(r); |
44510
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
759 |
// in this case node() won't ever return None |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
760 |
nt.insert(&*idx, idx.node(rev).unwrap(), rev) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
761 |
.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
|
762 |
} |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
763 |
|
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
764 |
*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
|
765 |
|
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
766 |
Ok(py.None()) |
15febf99a9c6
rust-nodemap: add binding to `nodemap_update_data`
Georges Racinet <georges.racinet@octobus.net>
parents:
44509
diff
changeset
|
767 |
} |
51202
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
768 |
|
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
769 |
fn inner_getitem(&self, py: Python, key: PyObject) -> PyResult<PyObject> { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
770 |
let idx = self.index(py).borrow(); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
771 |
Ok(match key.extract::<BaseRevision>(py) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
772 |
Ok(key_as_int) => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
773 |
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
|
774 |
RevisionDataParams::default() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
775 |
} else { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
776 |
let rev = UncheckedRevision(key_as_int); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
777 |
match idx.entry_as_params(rev) { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
778 |
Some(e) => e, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
779 |
None => { |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
780 |
return Err(PyErr::new::<IndexError, _>( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
781 |
py, |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
782 |
"revlog index out of range", |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
783 |
)); |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
784 |
} |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
785 |
} |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
786 |
}; |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
787 |
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
|
788 |
.into_object() |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
789 |
} |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
790 |
_ => self.get_rev(py, key.extract::<PyBytes>(py)?)?.map_or_else( |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
791 |
|| py.None(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
792 |
|py_rev| py_rev.into_py_object(py).into_object(), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
793 |
), |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
794 |
}) |
002b49905aac
rust-index: implementation of __getitem__
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51201
diff
changeset
|
795 |
} |
51212
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
796 |
|
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
|
797 |
fn inner_head_node_ids(&self, py: Python) -> PyResult<PyObject> { |
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
|
798 |
let index = &*self.index(py).borrow(); |
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
|
799 |
|
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
|
800 |
// 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
|
801 |
// 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
|
802 |
// 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
|
803 |
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
|
804 |
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
|
805 |
.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
|
806 |
.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
|
807 |
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
|
808 |
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
|
809 |
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
|
810 |
.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
|
811 |
.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
|
812 |
.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
|
813 |
) |
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
|
814 |
.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
|
815 |
}) |
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
|
816 |
.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
|
817 |
|
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
818 |
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
|
819 |
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
|
820 |
|
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
|
821 |
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
|
822 |
} |
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
|
823 |
|
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
824 |
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
|
825 |
&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
|
826 |
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
|
827 |
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
|
828 |
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
|
829 |
) -> PyResult<PyObject> { |
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
|
830 |
let index = &*self.index(py).borrow(); |
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
|
831 |
let stop_rev = match stop_rev.is_none(py) { |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
832 |
false => { |
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
|
833 |
let rev = stop_rev.extract::<i32>(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
|
834 |
if 0 <= rev && rev < index.len() as BaseRevision { |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
835 |
Some(Revision(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
|
836 |
} 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
|
837 |
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
|
838 |
} |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
839 |
} |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
840 |
true => 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
|
841 |
}; |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
842 |
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
|
843 |
(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
|
844 |
(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
|
845 |
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
|
846 |
} |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
847 |
_ => { |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
848 |
let filtered_revs = |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
849 |
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
|
850 |
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
|
851 |
&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
|
852 |
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
|
853 |
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
|
854 |
) |
51967
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
855 |
} |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
856 |
}; |
69bfd6b242ed
head-revs: merge the two inner_headrevs? variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51966
diff
changeset
|
857 |
|
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
|
858 |
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
|
859 |
// 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
|
860 |
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
|
861 |
.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
|
862 |
.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
|
863 |
|
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
|
864 |
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
|
865 |
.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
|
866 |
.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
|
867 |
.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
|
868 |
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
|
869 |
} 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
|
870 |
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
|
871 |
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
|
872 |
{ |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
873 |
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
|
874 |
} |
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
875 |
|
609700e5d8df
head-revs: add a native implementation of the `stop_rev` parameter
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51967
diff
changeset
|
876 |
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
|
877 |
.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
|
878 |
.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
|
879 |
.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
|
880 |
.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
|
881 |
.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
|
882 |
.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
|
883 |
} |
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
|
884 |
} |
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
|
885 |
|
51394
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
886 |
fn check_revision( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
887 |
index: &hg::index::Index, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
888 |
rev: UncheckedRevision, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
889 |
py: Python, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
890 |
) -> PyResult<Revision> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
891 |
index |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
892 |
.check_revision(rev) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
893 |
.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
|
894 |
} |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
895 |
|
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
896 |
fn inner_headrevsdiff( |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
897 |
&self, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
898 |
py: Python, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
899 |
begin: &PyObject, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
900 |
end: &PyObject, |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
901 |
) -> PyResult<PyObject> { |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
902 |
let begin = begin.extract::<BaseRevision>(py)?; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
903 |
let end = end.extract::<BaseRevision>(py)?; |
51463
a43a6d4b3be6
rust-index: don't use mutable borrow for head-diff computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51423
diff
changeset
|
904 |
let index = &*self.index(py).borrow(); |
51394
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
905 |
let begin = |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
906 |
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
|
907 |
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
|
908 |
let (removed, added) = index |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
909 |
.head_revs_diff(begin, end) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
910 |
.map_err(|e| graph_error(py, e))?; |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
911 |
let removed: Vec<_> = |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
912 |
removed.into_iter().map(PyRevision::from).collect(); |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
913 |
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
|
914 |
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
|
915 |
Ok(res) |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
916 |
} |
b01e7d97e167
revlog: add a Rust implementation of `headrevsdiff`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
51260
diff
changeset
|
917 |
|
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
918 |
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
|
919 |
&self, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
920 |
new_heads: &[Revision], |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
921 |
py: Python<'_>, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
922 |
) -> PyList { |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
923 |
let index = self.index(py).borrow(); |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
924 |
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
|
925 |
.iter() |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
926 |
.map(|r| { |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
927 |
PyBytes::new( |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
928 |
py, |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
929 |
index |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
930 |
.node(*r) |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
931 |
.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
|
932 |
.as_bytes(), |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
933 |
) |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
934 |
.into_object() |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
935 |
}) |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
936 |
.collect(); |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
937 |
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
|
938 |
*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
|
939 |
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
|
940 |
new_heads_py_list |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
941 |
} |
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
942 |
|
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
943 |
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
|
944 |
&self, |
51260
5b4995b40db0
rust-index: cache the head nodeids python list
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51259
diff
changeset
|
945 |
new_heads: &[Revision], |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
946 |
py: Python<'_>, |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
947 |
) -> PyList { |
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
948 |
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
|
949 |
.iter() |
898674a4dbc7
rust-index: headrevsfiltered() returning Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51213
diff
changeset
|
950 |
.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
|
951 |
.collect(); |
51258
9088c6d65ef6
rust-index-cpython: cache the heads' PyList representation
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51255
diff
changeset
|
952 |
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
|
953 |
*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
|
954 |
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
|
955 |
new_heads_py_list |
51213
9f876765cbe2
rust-index: add support for `headrevsfiltered`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51212
diff
changeset
|
956 |
} |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
957 |
|
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
958 |
fn inner_ancestors( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
959 |
&self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
960 |
py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
961 |
py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
962 |
) -> PyResult<PyObject> { |
51231
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51230
diff
changeset
|
963 |
let index = &*self.index(py).borrow(); |
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
964 |
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
|
965 |
let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
966 |
.ancestors(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
967 |
.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
|
968 |
.iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
969 |
.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
|
970 |
.collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
971 |
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
|
972 |
} |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
973 |
|
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
974 |
fn inner_commonancestorsheads( |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
975 |
&self, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
976 |
py: Python, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
977 |
py_revs: &PyTuple, |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
978 |
) -> PyResult<PyObject> { |
51231
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51230
diff
changeset
|
979 |
let index = &*self.index(py).borrow(); |
51222
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
980 |
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
|
981 |
let as_vec: Vec<_> = index |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
982 |
.common_ancestor_heads(&revs) |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
983 |
.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
|
984 |
.iter() |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
985 |
.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
|
986 |
.collect(); |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
987 |
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
|
988 |
} |
89ce6a49bfeb
rust-index: implement common_ancestors_heads() and ancestors()
Georges Racinet <georges.racinet@octobus.net>
parents:
51219
diff
changeset
|
989 |
|
51217
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
990 |
fn inner_computephasesmapsets( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
991 |
&self, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
992 |
py: Python, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
993 |
py_roots: PyDict, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
994 |
) -> PyResult<PyObject> { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
995 |
let index = &*self.index(py).borrow(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
996 |
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
|
997 |
.items_list(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
998 |
.iter(py) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
999 |
.map(|r| { |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1000 |
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
|
1001 |
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
|
1002 |
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
|
1003 |
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
|
1004 |
.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
|
1005 |
Ok((phase?, revs)) |
51217
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1006 |
}) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1007 |
.collect(); |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1008 |
let (len, phase_maps) = index |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1009 |
.compute_phases_map_sets(roots?) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1010 |
.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
|
1011 |
|
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1012 |
// Ugly hack, but temporary |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1013 |
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
|
1014 |
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
|
1015 |
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
|
1016 |
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
|
1017 |
// 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
|
1018 |
// it to `PySet::new`. |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1019 |
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
|
1020 |
for rev in roots { |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1021 |
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
|
1022 |
} |
3099f1c68afd
rust-index: remove one collect when converting back
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51403
diff
changeset
|
1023 |
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
|
1024 |
} |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1025 |
Ok(PyTuple::new( |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1026 |
py, |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1027 |
&[ |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1028 |
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
|
1029 |
py_phase_maps.into_object(), |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1030 |
], |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1031 |
) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1032 |
.into_object()) |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1033 |
} |
c817d9f626d3
rust-index: add support for `computephasesmapsets`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51216
diff
changeset
|
1034 |
|
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1035 |
fn inner_slicechunktodensity( |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1036 |
&self, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1037 |
py: Python, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1038 |
revs: PyObject, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1039 |
target_density: f64, |
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1040 |
min_gap_size: usize, |
51216
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1041 |
) -> PyResult<PyObject> { |
51231
59183a19954e
rust-index: use interior mutability in head revs and caches
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51230
diff
changeset
|
1042 |
let index = &*self.index(py).borrow(); |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1043 |
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
|
1044 |
let as_nested_vec = |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1045 |
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
|
1046 |
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
|
1047 |
let mut py_chunk = Vec::new(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1048 |
for chunk in as_nested_vec { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1049 |
py_chunk.clear(); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1050 |
py_chunk.reserve_exact(chunk.len()); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1051 |
for rev in chunk { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1052 |
py_chunk.push( |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1053 |
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
|
1054 |
); |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1055 |
} |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1056 |
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
|
1057 |
} |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1058 |
// 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
|
1059 |
if res.len() == 1 { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1060 |
Ok(PyTuple::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1061 |
} else { |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1062 |
Ok(PyList::new(py, &res).into_object()) |
8cb31833b486
rust-index: slicechunktodensity returns Rust result
Georges Racinet <georges.racinet@octobus.net>
parents:
51215
diff
changeset
|
1063 |
} |
51215
0112803e6c01
rust-index: add support for `_slicechunktodensity`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51214
diff
changeset
|
1064 |
} |
51219
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1065 |
|
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1066 |
fn inner_reachableroots2( |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1067 |
&self, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1068 |
py: Python, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1069 |
min_root: UncheckedRevision, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1070 |
heads: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1071 |
roots: PyObject, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1072 |
include_path: bool, |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1073 |
) -> PyResult<PyObject> { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1074 |
let index = &*self.index(py).borrow(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1075 |
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
|
1076 |
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
|
1077 |
})?; |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1078 |
let roots: Result<_, _> = roots |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1079 |
.iter(py)? |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1080 |
.map(|r| { |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1081 |
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
|
1082 |
Ok(r) => Ok(UncheckedRevision(r.0)), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1083 |
Err(e) => Err(e), |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1084 |
}) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1085 |
}) |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1086 |
.collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1087 |
let as_set = index |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1088 |
.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
|
1089 |
.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
|
1090 |
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
|
1091 |
.iter() |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1092 |
.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
|
1093 |
.collect(); |
fc05dd74e907
rust-index: add support for `reachableroots2`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51217
diff
changeset
|
1094 |
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
|
1095 |
} |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1096 |
} |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1097 |
|
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1098 |
py_class!(pub class NodeTree |py| { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1099 |
data nt: RefCell<CoreNodeTree>; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1100 |
data index: RefCell<UnsafePyLeaked<PySharedIndex>>; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1101 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1102 |
def __new__(_cls, index: PyObject) -> PyResult<NodeTree> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1103 |
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
|
1104 |
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
|
1105 |
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
|
1106 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1107 |
|
51248
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1108 |
/// 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
|
1109 |
/// |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1110 |
/// 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
|
1111 |
/// 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
|
1112 |
/// 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
|
1113 |
/// (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
|
1114 |
/// been meanwhile mutated. |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1115 |
def is_invalidated(&self) -> PyResult<bool> { |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1116 |
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
|
1117 |
// 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
|
1118 |
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
|
1119 |
// 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
|
1120 |
// - 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
|
1121 |
// - 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
|
1122 |
// 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
|
1123 |
// 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
|
1124 |
Ok(result.is_err()) |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1125 |
} |
0409bd6ba663
rust-revlog: add invalidation detection to `NodeTree` class
Georges Racinet <georges.racinet@octobus.net>
parents:
51247
diff
changeset
|
1126 |
|
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1127 |
def insert(&self, rev: PyRevision) -> PyResult<PyObject> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1128 |
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
|
1129 |
// 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
|
1130 |
let index = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1131 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1132 |
let rev = UncheckedRevision(rev.0); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1133 |
let rev = index |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1134 |
.check_revision(rev) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1135 |
.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
|
1136 |
if rev == NULL_REVISION { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1137 |
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
|
1138 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1139 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1140 |
let entry = index.inner.get_entry(rev).unwrap(); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1141 |
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
|
1142 |
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
|
1143 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1144 |
Ok(py.None()) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1145 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1146 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1147 |
/// 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
|
1148 |
/// |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1149 |
/// 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
|
1150 |
/// 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
|
1151 |
def prefix_rev_lookup( |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1152 |
&self, |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1153 |
node_prefix: PyBytes |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1154 |
) -> PyResult<Option<PyRevision>> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1155 |
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
|
1156 |
.map_err(|_| PyErr::new::<ValueError, _>( |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1157 |
py, |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1158 |
format!("Invalid node or prefix {:?}", |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1159 |
node_prefix.as_object())) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1160 |
)?; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1161 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1162 |
let nt = self.nt(py).borrow(); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1163 |
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
|
1164 |
// 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
|
1165 |
let index = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1166 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1167 |
Ok(nt.find_bin(index, prefix) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1168 |
.map_err(|e| nodemap_error(py, e))? |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1169 |
.map(|r| r.into()) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1170 |
) |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1171 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1172 |
|
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1173 |
def shortest(&self, node: PyBytes) -> PyResult<usize> { |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1174 |
let nt = self.nt(py).borrow(); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1175 |
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
|
1176 |
// 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
|
1177 |
let idx = &*unsafe { leaked.try_borrow(py)? }; |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1178 |
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
|
1179 |
{ |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1180 |
Ok(Some(l)) => Ok(l), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1181 |
Ok(None) => Err(revlog_error(py)), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1182 |
Err(e) => Err(nodemap_error(py, e)), |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1183 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1184 |
} |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1185 |
}); |
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1186 |
|
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1187 |
fn revlog_error(py: Python) -> PyErr { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1188 |
match py |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1189 |
.import("mercurial.error") |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1190 |
.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
|
1191 |
{ |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1192 |
Err(e) => e, |
47305
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
1193 |
Ok(cls) => PyErr::from_instance( |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
1194 |
py, |
33e7508b0ae9
hg-cpython: fix new occuring TypeError
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47268
diff
changeset
|
1195 |
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
|
1196 |
), |
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1197 |
} |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1198 |
} |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1199 |
|
51228
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1200 |
fn revlog_error_with_msg(py: Python, msg: &[u8]) -> PyErr { |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1201 |
match py |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1202 |
.import("mercurial.error") |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1203 |
.and_then(|m| m.get(py, "RevlogError")) |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1204 |
{ |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1205 |
Err(e) => e, |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1206 |
Ok(cls) => PyErr::from_instance( |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1207 |
py, |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1208 |
cls.call(py, (PyBytes::new(py, msg),), None) |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1209 |
.ok() |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1210 |
.into_py_object(py), |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1211 |
), |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1212 |
} |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1213 |
} |
5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51226
diff
changeset
|
1214 |
|
51212
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
1215 |
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
|
1216 |
// ParentOutOfRange is currently the only alternative |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
1217 |
// 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
|
1218 |
PyErr::new::<ValueError, _>(py, "parent out of range") |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
1219 |
} |
a7bba7df9189
rust-index: implement headrevs
Rapha?l Gom?s <rgomes@octobus.net>
parents:
51211
diff
changeset
|
1220 |
|
51196
44fbb7dfb563
rust-index: renamed nodemap error function for rev not in index
Georges Racinet <georges.racinet@octobus.net>
parents:
51195
diff
changeset
|
1221 |
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
|
1222 |
PyErr::new::<ValueError, _>( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1223 |
py, |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1224 |
format!( |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1225 |
"Inconsistency: Revision {} found in nodemap \ |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1226 |
is not in revlog index", |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1227 |
rev |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1228 |
), |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1229 |
) |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1230 |
} |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1231 |
|
51197
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
1232 |
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
|
1233 |
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
|
1234 |
py, |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
1235 |
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
|
1236 |
) |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
1237 |
} |
bc4d83047c6c
rust-index: helper for revision not in index not involving nodemap
Georges Racinet <georges.racinet@octobus.net>
parents:
51196
diff
changeset
|
1238 |
|
44506
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1239 |
/// Standard treatment of NodeMapError |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1240 |
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
|
1241 |
match err { |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1242 |
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
|
1243 |
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
|
1244 |
} |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1245 |
} |
26dd35ac59b8
rust-nodemap: add utils for propagating errors
Georges Racinet <georges.racinet@octobus.net>
parents:
44503
diff
changeset
|
1246 |
|
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1247 |
/// 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
|
1248 |
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
|
1249 |
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
|
1250 |
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
|
1251 |
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
|
1252 |
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
|
1253 |
|
51251
f94c10334bcb
rust-index: renamed `MixedIndex` as `Index`
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents:
51250
diff
changeset
|
1254 |
m.add_class::<Index>(py)?; |
51246
2966b88d4531
rust-revlog: bare minimal NodeTree exposition
Georges Racinet <georges.racinet@octobus.net>
parents:
51245
diff
changeset
|
1255 |
m.add_class::<NodeTree>(py)?; |
43961
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1256 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1257 |
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
|
1258 |
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
|
1259 |
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
|
1260 |
|
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1261 |
Ok(m) |
b69d5f3a41d0
rust-index: add a struct wrapping the C index
Georges Racinet <georges.racinet@octobus.net>
parents:
43945
diff
changeset
|
1262 |
} |