##// END OF EJS Templates
hg-core: fix path encoding usage...
Antoine cezar -
r46397:c0277679 default draft
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 6 // GNU General Public License version 2 or any later version.
7 7
8 8 use std::convert::From;
9 use std::path::PathBuf;
9 use std::path::{Path, PathBuf};
10 10
11 11 use crate::revlog::changelog::Changelog;
12 12 use crate::revlog::manifest::{Manifest, ManifestEntry};
@@ -14,7 +14,8 b' use crate::revlog::path_encode::path_enc'
14 14 use crate::revlog::revlog::Revlog;
15 15 use crate::revlog::revlog::RevlogError;
16 16 use crate::revlog::Revision;
17 use crate::utils::hg_path::HgPathBuf;
17 use crate::utils::files::get_path_from_bytes;
18 use crate::utils::hg_path::{HgPath, HgPathBuf};
18 19
19 20 const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n'];
20 21
@@ -121,15 +122,13 b" impl<'a> CatRev<'a> {"
121 122 {
122 123 for cat_file in self.files.iter() {
123 124 if cat_file.as_bytes() == manifest_file.as_bytes() {
124 let encoded_bytes =
125 path_encode(manifest_file.as_bytes());
126 let revlog_index_string = format!(
127 ".hg/store/data/{}.i",
128 String::from_utf8_lossy(&encoded_bytes),
129 );
130 let revlog_index_path =
131 self.root.join(&revlog_index_string);
132 let file_log = Revlog::open(&revlog_index_path)?;
125 let index_path =
126 store_path(self.root, manifest_file, b".i");
127 let data_path =
128 store_path(self.root, manifest_file, b".d");
129
130 let file_log =
131 Revlog::open(&index_path, Some(&data_path))?;
133 132 let file_node = hex::decode(&node_bytes)
134 133 .map_err(|_| CatRevErrorKind::CorruptedRevlog)?;
135 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 102 DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"),
103 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 106 let data = revlog.get_rev_data(rev)?;
107 107
108 108 Ok(data)
@@ -12,7 +12,7 b' impl Changelog {'
12 12 /// Open the `changelog` of a repository given by its root.
13 13 pub fn open(root: &PathBuf) -> Result<Self, RevlogError> {
14 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 16 Ok(Self { revlog })
17 17 }
18 18
@@ -13,7 +13,7 b' impl Manifest {'
13 13 /// Open the `manifest` of a repository given by its root.
14 14 pub fn open(root: &PathBuf) -> Result<Self, RevlogError> {
15 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 17 Ok(Self { revlog })
18 18 }
19 19
@@ -47,7 +47,10 b' impl Revlog {'
47 47 /// It will also open the associated data file if index and data are not
48 48 /// interleaved.
49 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 54 let index_mmap =
52 55 mmap_open(&index_path).map_err(RevlogError::IoError)?;
53 56
@@ -58,16 +61,17 b' impl Revlog {'
58 61
59 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 66 // type annotation required
63 67 // won't recognize Mmap as Deref<Target = [u8]>
64 68 let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> =
65 69 if index.is_inline() {
66 70 None
67 71 } else {
68 let data_path = index_path.with_extension("d");
72 let data_path = data_path.unwrap_or(&default_data_path);
69 73 let data_mmap =
70 mmap_open(&data_path).map_err(RevlogError::IoError)?;
74 mmap_open(data_path).map_err(RevlogError::IoError)?;
71 75 Some(Box::new(data_mmap))
72 76 };
73 77
General Comments 0
You need to be logged in to leave comments. Login now