20 PythonObject, ToPyObject, UnsafePyLeaked, |
20 PythonObject, ToPyObject, UnsafePyLeaked, |
21 }; |
21 }; |
22 use hg::{ |
22 use hg::{ |
23 errors::HgError, |
23 errors::HgError, |
24 fncache::FnCache, |
24 fncache::FnCache, |
25 index::{Phase, RevisionDataParams, SnapshotsCache, INDEX_ENTRY_SIZE}, |
|
26 nodemap::{Block, NodeMapError, NodeTree as CoreNodeTree}, |
|
27 revlog::{ |
25 revlog::{ |
28 compression::CompressionConfig, |
26 compression::CompressionConfig, |
|
27 index::{ |
|
28 Index, IndexHeader, Phase, RevisionDataParams, SnapshotsCache, |
|
29 INDEX_ENTRY_SIZE, |
|
30 }, |
29 inner_revlog::{InnerRevlog as CoreInnerRevlog, RevisionBuffer}, |
31 inner_revlog::{InnerRevlog as CoreInnerRevlog, RevisionBuffer}, |
30 nodemap::NodeMap, |
32 nodemap::{Block, NodeMap, NodeMapError, NodeTree as CoreNodeTree}, |
31 options::{ |
33 options::{ |
32 RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig, |
34 RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig, |
33 RevlogOpenOptions, |
35 RevlogOpenOptions, |
34 }, |
36 }, |
35 Graph, NodePrefix, RevlogError, RevlogIndex, |
37 Graph, NodePrefix, RevlogError, RevlogIndex, RevlogType, |
36 }, |
38 }, |
37 transaction::Transaction, |
39 transaction::Transaction, |
38 utils::files::{get_bytes_from_path, get_path_from_bytes}, |
40 utils::files::{get_bytes_from_path, get_path_from_bytes}, |
39 vfs::FnCacheVfs, |
41 vfs::FnCacheVfs, |
40 BaseRevision, Node, Revision, RevlogType, UncheckedRevision, |
42 BaseRevision, Node, Revision, UncheckedRevision, NULL_REVISION, |
41 NULL_REVISION, |
|
42 }; |
43 }; |
43 use std::{ |
44 use std::{ |
44 cell::{Cell, RefCell}, |
45 cell::{Cell, RefCell}, |
45 collections::{HashMap, HashSet}, |
46 collections::{HashMap, HashSet}, |
46 sync::atomic::{AtomicBool, AtomicUsize, Ordering}, |
47 sync::atomic::{AtomicBool, AtomicUsize, Ordering}, |
48 }; |
49 }; |
49 use vcsgraph::graph::Graph as VCSGraph; |
50 use vcsgraph::graph::Graph as VCSGraph; |
50 |
51 |
51 pub struct PySharedIndex { |
52 pub struct PySharedIndex { |
52 /// The underlying hg-core index |
53 /// The underlying hg-core index |
53 pub(crate) inner: &'static hg::index::Index, |
54 pub(crate) inner: &'static Index, |
54 } |
55 } |
55 |
56 |
56 /// Return a Struct implementing the Graph trait |
57 /// Return a Struct implementing the Graph trait |
57 pub(crate) fn py_rust_index_to_graph( |
58 pub(crate) fn py_rust_index_to_graph( |
58 py: Python, |
59 py: Python, |
987 let path = path.extract::<PyBytes>(py)?; |
988 let path = path.extract::<PyBytes>(py)?; |
988 Some(get_path_from_bytes(path.data(py)).to_owned()) |
989 Some(get_path_from_bytes(path.data(py)).to_owned()) |
989 }, |
990 }, |
990 None => None, |
991 None => None, |
991 }; |
992 }; |
992 let header = hg::index::IndexHeader::parse(&header.to_be_bytes()); |
993 let header = IndexHeader::parse(&header.to_be_bytes()); |
993 let header = header.expect("invalid header bytes"); |
994 let header = header.expect("invalid header bytes"); |
994 let path = inner |
995 let path = inner |
995 .split_inline(header, new_index_file_path) |
996 .split_inline(header, new_index_file_path) |
996 .map_err(|e| revlog_error_from_msg(py, e))?; |
997 .map_err(|e| revlog_error_from_msg(py, e))?; |
997 Ok(PyBytes::new(py, &get_bytes_from_path(path))) |
998 Ok(PyBytes::new(py, &get_bytes_from_path(path))) |
1997 feature_config, |
1998 feature_config, |
1998 ); |
1999 ); |
1999 |
2000 |
2000 // Safety: we keep the buffer around inside the class as `index_mmap` |
2001 // Safety: we keep the buffer around inside the class as `index_mmap` |
2001 let (buf, bytes) = unsafe { mmap_keeparound(py, index_data)? }; |
2002 let (buf, bytes) = unsafe { mmap_keeparound(py, index_data)? }; |
2002 let index = hg::index::Index::new(bytes, options.index_header()) |
2003 let index = Index::new(bytes, options.index_header()) |
2003 .map_err(|e| revlog_error_from_msg(py, e))?; |
2004 .map_err(|e| revlog_error_from_msg(py, e))?; |
2004 |
2005 |
2005 let base = &vfs_base.extract::<PyBytes>(py)?; |
2006 let base = &vfs_base.extract::<PyBytes>(py)?; |
2006 let base = get_path_from_bytes(base.data(py)).to_owned(); |
2007 let base = get_path_from_bytes(base.data(py)).to_owned(); |
2007 let core = CoreInnerRevlog::new( |
2008 let core = CoreInnerRevlog::new( |