equal
deleted
inserted
replaced
14 use super::nodemap; |
14 use super::nodemap; |
15 use super::nodemap::{NodeMap, NodeMapError}; |
15 use super::nodemap::{NodeMap, NodeMapError}; |
16 use super::nodemap_docket::NodeMapDocket; |
16 use super::nodemap_docket::NodeMapDocket; |
17 use super::patch; |
17 use super::patch; |
18 use crate::errors::HgError; |
18 use crate::errors::HgError; |
19 use crate::repo::Repo; |
|
20 use crate::revlog::Revision; |
19 use crate::revlog::Revision; |
|
20 use crate::vfs::Vfs; |
21 use crate::{Node, NULL_REVISION}; |
21 use crate::{Node, NULL_REVISION}; |
22 |
22 |
23 const REVISION_FLAG_CENSORED: u16 = 1 << 15; |
23 const REVISION_FLAG_CENSORED: u16 = 1 << 15; |
24 const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14; |
24 const REVISION_FLAG_ELLIPSIS: u16 = 1 << 14; |
25 const REVISION_FLAG_EXTSTORED: u16 = 1 << 13; |
25 const REVISION_FLAG_EXTSTORED: u16 = 1 << 13; |
79 /// |
79 /// |
80 /// It will also open the associated data file if index and data are not |
80 /// It will also open the associated data file if index and data are not |
81 /// interleaved. |
81 /// interleaved. |
82 #[timed] |
82 #[timed] |
83 pub fn open( |
83 pub fn open( |
84 repo: &Repo, |
84 store_vfs: &Vfs, |
85 index_path: impl AsRef<Path>, |
85 index_path: impl AsRef<Path>, |
86 data_path: Option<&Path>, |
86 data_path: Option<&Path>, |
87 use_nodemap: bool, |
87 use_nodemap: bool, |
88 ) -> Result<Self, HgError> { |
88 ) -> Result<Self, HgError> { |
89 let index_path = index_path.as_ref(); |
89 let index_path = index_path.as_ref(); |
90 let index = { |
90 let index = { |
91 match repo.store_vfs().mmap_open_opt(&index_path)? { |
91 match store_vfs.mmap_open_opt(&index_path)? { |
92 None => Index::new(Box::new(vec![])), |
92 None => Index::new(Box::new(vec![])), |
93 Some(index_mmap) => { |
93 Some(index_mmap) => { |
94 let index = Index::new(Box::new(index_mmap))?; |
94 let index = Index::new(Box::new(index_mmap))?; |
95 Ok(index) |
95 Ok(index) |
96 } |
96 } |
104 let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> = |
104 let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> = |
105 if index.is_inline() { |
105 if index.is_inline() { |
106 None |
106 None |
107 } else { |
107 } else { |
108 let data_path = data_path.unwrap_or(&default_data_path); |
108 let data_path = data_path.unwrap_or(&default_data_path); |
109 let data_mmap = repo.store_vfs().mmap_open(data_path)?; |
109 let data_mmap = store_vfs.mmap_open(data_path)?; |
110 Some(Box::new(data_mmap)) |
110 Some(Box::new(data_mmap)) |
111 }; |
111 }; |
112 |
112 |
113 let nodemap = if index.is_inline() { |
113 let nodemap = if index.is_inline() { |
114 None |
114 None |
115 } else if !use_nodemap { |
115 } else if !use_nodemap { |
116 None |
116 None |
117 } else { |
117 } else { |
118 NodeMapDocket::read_from_file(&repo.store_vfs(), index_path)?.map( |
118 NodeMapDocket::read_from_file(store_vfs, index_path)?.map( |
119 |(docket, data)| { |
119 |(docket, data)| { |
120 nodemap::NodeTree::load_bytes( |
120 nodemap::NodeTree::load_bytes( |
121 Box::new(data), |
121 Box::new(data), |
122 docket.data_length, |
122 docket.data_length, |
123 ) |
123 ) |