rust/hg-pyo3/src/revlog/mod.rs
author Georges Racinet <georges.racinet@cloudcrane.io>
Wed, 25 Dec 2024 15:38:18 +0100
changeset 52784 5e3e8876fd9e
parent 52782 827889802d11
child 52786 4e34e8fd46d4
permissions -rw-r--r--
rust-pyo3-revlog: index and nodetree read accessor helpers These are similar to what Python calls context managers: they enclose neatly the intermediate `self_ref` and will allow writing caller code that focuses on its own application logic.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     1
// revlog.rs
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     2
//
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     3
// Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     4
//           2020-2024 Raphaël Gomès <raphael.gomes@octobus.net>
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     5
//           2024 Georges Racinet <georges.racinet@cloudcrane.io>
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     6
//
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     7
// This software may be used and distributed according to the terms of the
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
     8
// GNU General Public License version 2 or any later version.
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
     9
use pyo3::buffer::PyBuffer;
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
    10
use pyo3::prelude::*;
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    11
use pyo3::types::{PyBytes, PyBytesMethods, PyList};
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    12
use pyo3_sharedref::PyShareable;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    13
52784
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
    14
use std::sync::{atomic::AtomicUsize, RwLock, RwLockReadGuard};
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
    15
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    16
use hg::{
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    17
    revlog::{
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    18
        index::Index, inner_revlog::InnerRevlog as CoreInnerRevlog,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    19
        nodemap::NodeTree as CoreNodeTree, options::RevlogOpenOptions,
52782
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
    20
        RevlogIndex, RevlogType,
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    21
    },
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    22
    utils::files::get_path_from_bytes,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    23
    vfs::FnCacheVfs,
52782
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
    24
    BaseRevision, Revision,
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    25
};
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    26
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    27
use crate::{
52784
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
    28
    exceptions::{
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
    29
        map_lock_error, map_try_lock_error, nodemap_error,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
    30
        revlog_error_from_msg,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
    31
    },
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    32
    store::PyFnCache,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    33
    util::{new_submodule, take_buffer_with_slice},
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    34
};
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
    35
52778
523ca3d225f5 rust-pyo3-revlog: config extraction functions
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52775
diff changeset
    36
mod config;
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    37
use config::*;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    38
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    39
#[pyclass]
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    40
#[allow(dead_code)]
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    41
struct InnerRevlog {
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    42
    irl: PyShareable<CoreInnerRevlog>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    43
    nt: RwLock<Option<CoreNodeTree>>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    44
    docket: Option<PyObject>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    45
    // Holds a reference to the mmap'ed persistent nodemap data
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    46
    nodemap_mmap: Option<PyBuffer<u8>>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    47
    // Holds a reference to the mmap'ed persistent index data
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    48
    index_mmap: Option<PyBuffer<u8>>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    49
    revision_cache: Option<PyObject>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    50
    head_revs_py_list: Option<Py<PyList>>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    51
    head_node_ids_py_list: Option<Py<PyList>>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    52
    use_persistent_nodemap: bool,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    53
    nodemap_queries: AtomicUsize,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    54
}
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    55
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    56
#[pymethods]
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    57
impl InnerRevlog {
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    58
    #[new]
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    59
    // The Python side has authority on this signature.
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    60
    #[allow(clippy::too_many_arguments)]
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    61
    fn new(
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    62
        vfs_base: &Bound<'_, PyBytes>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    63
        fncache: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    64
        vfs_is_readonly: bool,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    65
        index_data: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    66
        index_file: &Bound<'_, PyBytes>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    67
        data_file: &Bound<'_, PyBytes>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    68
        sidedata_file: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    69
        inline: bool,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    70
        data_config: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    71
        delta_config: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    72
        feature_config: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    73
        chunk_cache: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    74
        default_compression_header: &Bound<'_, PyAny>,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    75
        revlog_type: usize,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    76
        use_persistent_nodemap: bool,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    77
    ) -> PyResult<Self> {
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    78
        // Let clippy accept the unused arguments. This is a bit better than
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    79
        // a blank `allow` directive
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    80
        let _ = sidedata_file;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    81
        let _ = chunk_cache;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    82
        let _ = default_compression_header;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    83
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    84
        let index_file = get_path_from_bytes(index_file.as_bytes()).to_owned();
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    85
        let data_file = get_path_from_bytes(data_file.as_bytes()).to_owned();
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    86
        let revlog_type = RevlogType::try_from(revlog_type)
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    87
            .map_err(revlog_error_from_msg)?;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    88
        let data_config = extract_data_config(data_config, revlog_type)?;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    89
        let delta_config = extract_delta_config(delta_config, revlog_type)?;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    90
        let feature_config =
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    91
            extract_feature_config(feature_config, revlog_type)?;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    92
        let options = RevlogOpenOptions::new(
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    93
            inline,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    94
            data_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    95
            delta_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    96
            feature_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    97
        );
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    98
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
    99
        // Safety: we keep the buffer around inside the returned instance as
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   100
        // `index_mmap`
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   101
        let (buf, bytes) = unsafe { take_buffer_with_slice(index_data)? };
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   102
        let index = Index::new(bytes, options.index_header())
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   103
            .map_err(revlog_error_from_msg)?;
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   104
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   105
        let base = get_path_from_bytes(vfs_base.as_bytes()).to_owned();
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   106
        let core = CoreInnerRevlog::new(
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   107
            Box::new(FnCacheVfs::new(
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   108
                base,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   109
                vfs_is_readonly,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   110
                Box::new(PyFnCache::new(fncache.clone().unbind())),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   111
            )),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   112
            index,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   113
            index_file,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   114
            data_file,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   115
            data_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   116
            delta_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   117
            feature_config,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   118
        );
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   119
        Ok(Self {
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   120
            irl: core.into(),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   121
            nt: None.into(),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   122
            docket: None,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   123
            nodemap_mmap: None,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   124
            index_mmap: buf.into(),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   125
            head_revs_py_list: None,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   126
            head_node_ids_py_list: None,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   127
            revision_cache: None,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   128
            use_persistent_nodemap,
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   129
            nodemap_queries: AtomicUsize::new(0),
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   130
        })
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   131
    }
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   132
}
52778
523ca3d225f5 rust-pyo3-revlog: config extraction functions
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52775
diff changeset
   133
52782
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   134
impl InnerRevlog {
52784
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   135
    /// Take the lock on `slf.irl` for reading and call a closure.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   136
    ///
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   137
    /// This serves the purpose to keep the needed intermediate [`PyRef`]
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   138
    /// that must be obtained to access the data from the [`Bound`] reference
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   139
    /// and of which the locked [`CoreInnerRevlog`] depends.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   140
    /// This also provides releasing of the [`PyRef`] as soon as the closure
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   141
    /// is done, which is crucial if the caller needs to obtain a [`PyRefMut`]
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   142
    /// later on.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   143
    ///
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   144
    /// In the closure, we hand back the intermediate [`PyRef`] that
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   145
    /// has been generated so that the closure can access more attributes.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   146
    fn with_core_read<'py, T>(
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   147
        slf: &Bound<'py, Self>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   148
        f: impl FnOnce(
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   149
            &PyRef<'py, Self>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   150
            RwLockReadGuard<CoreInnerRevlog>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   151
        ) -> PyResult<T>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   152
    ) -> PyResult<T> {
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   153
        let self_ref = slf.borrow();
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   154
        // Safety: the owner is the right one. We will anyway
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   155
        // not actually `share` it. Perhaps pyo3-sharedref should provide
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   156
        // something less scary for this kind of usage.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   157
        let shareable_ref = unsafe { self_ref.irl.borrow_with_owner(slf) };
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   158
        let guard = shareable_ref.try_read().map_err(map_try_lock_error)?;
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   159
        f(&self_ref, guard)
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   160
    }
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   161
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   162
    #[allow(dead_code)]
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   163
    fn with_index_read<T>(
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   164
        slf: &Bound<'_, Self>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   165
        f: impl FnOnce(&Index) -> PyResult<T>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   166
    ) -> PyResult<T> {
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   167
        Self::with_core_read(slf, |_, guard| f(&guard.index))
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   168
    }
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   169
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   170
    /// Lock `slf` for reading and execute a closure on its [`Index`] and
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   171
    /// [`NodeTree`]
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   172
    ///
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   173
    /// The [`NodeTree`] is initialized an filled before hand if needed.
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   174
    #[allow(dead_code)]
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   175
    fn with_index_nt_read<T>(
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   176
        slf: &Bound<'_, Self>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   177
        f: impl FnOnce(&Index, &CoreNodeTree) -> PyResult<T>,
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   178
    ) -> PyResult<T> {
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   179
        Self::with_core_read(slf, |self_ref, guard| {
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   180
            let idx = &guard.index;
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   181
            let nt =
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   182
                self_ref.get_nodetree(idx)?.read().map_err(map_lock_error)?;
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   183
            let nt = nt.as_ref().expect("nodetree should be set");
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   184
            f(idx, nt)
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   185
        })
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   186
    }
5e3e8876fd9e rust-pyo3-revlog: index and nodetree read accessor helpers
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52782
diff changeset
   187
52782
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   188
    /// Fill a [`CoreNodeTree`] by doing a full iteration on the given
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   189
    /// [`Index`]
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   190
    ///
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   191
    /// # Python exceptions
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   192
    /// Raises `ValueError` if `nt` has existing data that is inconsistent
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   193
    /// with `idx`.
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   194
    fn fill_nodemap(idx: &Index, nt: &mut CoreNodeTree) -> PyResult<()> {
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   195
        for r in 0..idx.len() {
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   196
            let rev = Revision(r as BaseRevision);
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   197
            // in this case node() won't ever return None
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   198
            nt.insert(idx, idx.node(rev).expect("node should exist"), rev)
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   199
                .map_err(nodemap_error)?
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   200
        }
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   201
        Ok(())
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   202
    }
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   203
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   204
    /// Return a working NodeTree of this InnerRevlog
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   205
    ///
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   206
    /// In case the NodeTree has not been initialized yet (in particular
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   207
    /// not from persistent data at instantiation), it is created and
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   208
    /// filled right away from the index.
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   209
    ///
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   210
    /// Technically, the returned NodeTree is still behind the lock of
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   211
    /// the `nt` field, hence still wrapped in an [`Option`]. Callers
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   212
    /// will need to take the lock and unwrap with `expect()`.
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   213
    ///
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   214
    /// # Python exceptions
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   215
    /// The case mentioned in [`Self::fill_nodemap()`] cannot happen, as the
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   216
    /// NodeTree is empty when it is called.
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   217
    #[allow(dead_code)]
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   218
    fn get_nodetree(
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   219
        &self,
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   220
        idx: &Index,
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   221
    ) -> PyResult<&RwLock<Option<CoreNodeTree>>> {
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   222
        if self.nt.read().map_err(map_lock_error)?.is_none() {
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   223
            let readonly = Box::<Vec<_>>::default();
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   224
            let mut nt = CoreNodeTree::load_bytes(readonly, 0);
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   225
            Self::fill_nodemap(idx, &mut nt)?;
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   226
            self.nt.write().map_err(map_lock_error)?.replace(nt);
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   227
        }
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   228
        Ok(&self.nt)
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   229
    }
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   230
}
827889802d11 rust-pyo3-revlog: nodemap filling accessor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52780
diff changeset
   231
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   232
pub fn init_module<'py>(
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   233
    py: Python<'py>,
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   234
    package: &str,
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   235
) -> PyResult<Bound<'py, PyModule>> {
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   236
    let m = new_submodule(py, package, "revlog")?;
52780
42b219a1404a rust-pyo3-revlog: InnerRevlog definition and constructor
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 52778
diff changeset
   237
    m.add_class::<InnerRevlog>()?;
52775
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   238
    Ok(m)
264047bf4b9b rust-pyo3-revlog: new Python and Rust module
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
diff changeset
   239
}