Show More
@@ -6,7 +6,7 b'' | |||||
6 | // GNU General Public License version 2 or any later version. |
|
6 | // GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | use std::convert::From; |
|
8 | use std::convert::From; | |
9 | use std::path::PathBuf; |
|
9 | use std::path::{Path, PathBuf}; | |
10 |
|
10 | |||
11 | use crate::revlog::changelog::Changelog; |
|
11 | use crate::revlog::changelog::Changelog; | |
12 | use crate::revlog::manifest::{Manifest, ManifestEntry}; |
|
12 | use crate::revlog::manifest::{Manifest, ManifestEntry}; | |
@@ -14,7 +14,8 b' use crate::revlog::path_encode::path_enc' | |||||
14 | use crate::revlog::revlog::Revlog; |
|
14 | use crate::revlog::revlog::Revlog; | |
15 | use crate::revlog::revlog::RevlogError; |
|
15 | use crate::revlog::revlog::RevlogError; | |
16 | use crate::revlog::Revision; |
|
16 | use crate::revlog::Revision; | |
17 |
use crate::utils:: |
|
17 | use crate::utils::files::get_path_from_bytes; | |
|
18 | use crate::utils::hg_path::{HgPath, HgPathBuf}; | |||
18 |
|
19 | |||
19 | const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; |
|
20 | const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; | |
20 |
|
21 | |||
@@ -121,15 +122,13 b" impl<'a> CatRev<'a> {" | |||||
121 | { |
|
122 | { | |
122 | for cat_file in self.files.iter() { |
|
123 | for cat_file in self.files.iter() { | |
123 | if cat_file.as_bytes() == manifest_file.as_bytes() { |
|
124 | if cat_file.as_bytes() == manifest_file.as_bytes() { | |
124 |
let |
|
125 | let index_path = | |
125 |
path |
|
126 | store_path(self.root, manifest_file, b".i"); | |
126 |
let |
|
127 | let data_path = | |
127 |
" |
|
128 | store_path(self.root, manifest_file, b".d"); | |
128 | String::from_utf8_lossy(&encoded_bytes), |
|
129 | ||
129 |
|
|
130 | let file_log = | |
130 |
let |
|
131 | Revlog::open(&index_path, Some(&data_path))?; | |
131 | self.root.join(&revlog_index_string); |
|
|||
132 | let file_log = Revlog::open(&revlog_index_path)?; |
|
|||
133 | let file_node = hex::decode(&node_bytes) |
|
132 | let file_node = hex::decode(&node_bytes) | |
134 | .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; |
|
133 | .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; | |
135 | let file_rev = file_log.get_node_rev(&file_node)?; |
|
134 | let file_rev = file_log.get_node_rev(&file_node)?; | |
@@ -156,3 +155,15 b" impl<'a> CatRev<'a> {" | |||||
156 | } |
|
155 | } | |
157 | } |
|
156 | } | |
158 | } |
|
157 | } | |
|
158 | ||||
|
159 | fn store_path(root: &Path, hg_path: &HgPath, suffix: &[u8]) -> PathBuf { | |||
|
160 | let encoded_bytes = | |||
|
161 | path_encode(&[b"data/", hg_path.as_bytes(), suffix].concat()); | |||
|
162 | [ | |||
|
163 | root, | |||
|
164 | &Path::new(".hg/store/"), | |||
|
165 | get_path_from_bytes(&encoded_bytes), | |||
|
166 | ] | |||
|
167 | .iter() | |||
|
168 | .collect() | |||
|
169 | } |
@@ -102,7 +102,7 b" impl<'a> DebugData<'a> {" | |||||
102 | DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"), |
|
102 | DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"), | |
103 | DebugDataKind::Manifest => root.join(".hg/store/00manifest.i"), |
|
103 | DebugDataKind::Manifest => root.join(".hg/store/00manifest.i"), | |
104 | }; |
|
104 | }; | |
105 | let revlog = Revlog::open(&index_file)?; |
|
105 | let revlog = Revlog::open(&index_file, None)?; | |
106 | let data = revlog.get_rev_data(rev)?; |
|
106 | let data = revlog.get_rev_data(rev)?; | |
107 |
|
107 | |||
108 | Ok(data) |
|
108 | Ok(data) |
@@ -12,7 +12,7 b' impl Changelog {' | |||||
12 | /// Open the `changelog` of a repository given by its root. |
|
12 | /// Open the `changelog` of a repository given by its root. | |
13 | pub fn open(root: &PathBuf) -> Result<Self, RevlogError> { |
|
13 | pub fn open(root: &PathBuf) -> Result<Self, RevlogError> { | |
14 | let index_file = root.join(".hg/store/00changelog.i"); |
|
14 | let index_file = root.join(".hg/store/00changelog.i"); | |
15 | let revlog = Revlog::open(&index_file)?; |
|
15 | let revlog = Revlog::open(&index_file, None)?; | |
16 | Ok(Self { revlog }) |
|
16 | Ok(Self { revlog }) | |
17 | } |
|
17 | } | |
18 |
|
18 |
@@ -13,7 +13,7 b' impl Manifest {' | |||||
13 | /// Open the `manifest` of a repository given by its root. |
|
13 | /// Open the `manifest` of a repository given by its root. | |
14 | pub fn open(root: &PathBuf) -> Result<Self, RevlogError> { |
|
14 | pub fn open(root: &PathBuf) -> Result<Self, RevlogError> { | |
15 | let index_file = root.join(".hg/store/00manifest.i"); |
|
15 | let index_file = root.join(".hg/store/00manifest.i"); | |
16 | let revlog = Revlog::open(&index_file)?; |
|
16 | let revlog = Revlog::open(&index_file, None)?; | |
17 | Ok(Self { revlog }) |
|
17 | Ok(Self { revlog }) | |
18 | } |
|
18 | } | |
19 |
|
19 |
@@ -47,7 +47,10 b' impl Revlog {' | |||||
47 | /// It will also open the associated data file if index and data are not |
|
47 | /// It will also open the associated data file if index and data are not | |
48 | /// interleaved. |
|
48 | /// interleaved. | |
49 | #[timed] |
|
49 | #[timed] | |
50 | pub fn open(index_path: &Path) -> Result<Self, RevlogError> { |
|
50 | pub fn open( | |
|
51 | index_path: &Path, | |||
|
52 | data_path: Option<&Path>, | |||
|
53 | ) -> Result<Self, RevlogError> { | |||
51 | let index_mmap = |
|
54 | let index_mmap = | |
52 | mmap_open(&index_path).map_err(RevlogError::IoError)?; |
|
55 | mmap_open(&index_path).map_err(RevlogError::IoError)?; | |
53 |
|
56 | |||
@@ -58,16 +61,17 b' impl Revlog {' | |||||
58 |
|
61 | |||
59 | let index = Index::new(Box::new(index_mmap))?; |
|
62 | let index = Index::new(Box::new(index_mmap))?; | |
60 |
|
63 | |||
61 | // TODO load data only when needed // |
|
64 | let default_data_path = index_path.with_extension("d"); | |
|
65 | ||||
62 | // type annotation required |
|
66 | // type annotation required | |
63 | // won't recognize Mmap as Deref<Target = [u8]> |
|
67 | // won't recognize Mmap as Deref<Target = [u8]> | |
64 | let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> = |
|
68 | let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> = | |
65 | if index.is_inline() { |
|
69 | if index.is_inline() { | |
66 | None |
|
70 | None | |
67 | } else { |
|
71 | } else { | |
68 |
let data_path = |
|
72 | let data_path = data_path.unwrap_or(&default_data_path); | |
69 | let data_mmap = |
|
73 | let data_mmap = | |
70 |
mmap_open( |
|
74 | mmap_open(data_path).map_err(RevlogError::IoError)?; | |
71 | Some(Box::new(data_mmap)) |
|
75 | Some(Box::new(data_mmap)) | |
72 | }; |
|
76 | }; | |
73 |
|
77 |
General Comments 0
You need to be logged in to leave comments.
Login now