Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/revlog.rs @ 51188:13f58ce70299
rust-revlog: teach the revlog opening code to read the repo options
This will become necessary as we start writing revlog data from Rust.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 18 Sep 2023 17:11:11 +0200 |
parents | 6ec8387eb0be |
children | 65c9032e2e5a |
comparison
equal
deleted
inserted
replaced
51187:6ec8387eb0be | 51188:13f58ce70299 |
---|---|
15 exc::{IndexError, ValueError}, | 15 exc::{IndexError, ValueError}, |
16 ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule, | 16 ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyInt, PyModule, |
17 PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, | 17 PyObject, PyResult, PyString, PyTuple, Python, PythonObject, ToPyObject, |
18 }; | 18 }; |
19 use hg::{ | 19 use hg::{ |
20 index::IndexHeader, | |
20 nodemap::{Block, NodeMapError, NodeTree}, | 21 nodemap::{Block, NodeMapError, NodeTree}, |
21 revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex}, | 22 revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex}, |
22 BaseRevision, Revision, UncheckedRevision, | 23 BaseRevision, Revision, UncheckedRevision, |
23 }; | 24 }; |
24 use std::cell::RefCell; | 25 use std::cell::RefCell; |
45 data index_mmap: RefCell<Option<PyBuffer>>; | 46 data index_mmap: RefCell<Option<PyBuffer>>; |
46 | 47 |
47 def __new__( | 48 def __new__( |
48 _cls, | 49 _cls, |
49 cindex: PyObject, | 50 cindex: PyObject, |
50 data: PyObject | 51 data: PyObject, |
52 default_header: u32, | |
51 ) -> PyResult<MixedIndex> { | 53 ) -> PyResult<MixedIndex> { |
52 Self::new(py, cindex, data) | 54 Self::new(py, cindex, data, default_header) |
53 } | 55 } |
54 | 56 |
55 /// Compatibility layer used for Python consumers needing access to the C index | 57 /// Compatibility layer used for Python consumers needing access to the C index |
56 /// | 58 /// |
57 /// Only use case so far is `scmutil.shortesthexnodeidprefix`, | 59 /// Only use case so far is `scmutil.shortesthexnodeidprefix`, |
362 impl MixedIndex { | 364 impl MixedIndex { |
363 fn new( | 365 fn new( |
364 py: Python, | 366 py: Python, |
365 cindex: PyObject, | 367 cindex: PyObject, |
366 data: PyObject, | 368 data: PyObject, |
369 header: u32, | |
367 ) -> PyResult<MixedIndex> { | 370 ) -> PyResult<MixedIndex> { |
368 // Safety: we keep the buffer around inside the class as `index_mmap` | 371 // Safety: we keep the buffer around inside the class as `index_mmap` |
369 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; | 372 let (buf, bytes) = unsafe { mmap_keeparound(py, data)? }; |
370 | 373 |
371 Self::create_instance( | 374 Self::create_instance( |
372 py, | 375 py, |
373 RefCell::new(cindex::Index::new(py, cindex)?), | 376 RefCell::new(cindex::Index::new(py, cindex)?), |
374 RefCell::new(hg::index::Index::new(bytes).unwrap()), | 377 RefCell::new( |
378 hg::index::Index::new( | |
379 bytes, | |
380 IndexHeader::parse(&header.to_be_bytes()) | |
381 .expect("default header is broken") | |
382 .unwrap(), | |
383 ) | |
384 .unwrap(), | |
385 ), | |
375 RefCell::new(None), | 386 RefCell::new(None), |
376 RefCell::new(None), | 387 RefCell::new(None), |
377 RefCell::new(None), | 388 RefCell::new(None), |
378 RefCell::new(Some(buf)), | 389 RefCell::new(Some(buf)), |
379 ) | 390 ) |