Show More
@@ -14,7 +14,6 b' use crate::config::layer::{' | |||||
14 | use std::path::PathBuf; |
|
14 | use std::path::PathBuf; | |
15 |
|
15 | |||
16 | use crate::repo::Repo; |
|
16 | use crate::repo::Repo; | |
17 | use crate::utils::files::read_whole_file; |
|
|||
18 |
|
17 | |||
19 | /// Holds the config values for the current repository |
|
18 | /// Holds the config values for the current repository | |
20 | /// TODO update this docstring once we support more sources |
|
19 | /// TODO update this docstring once we support more sources | |
@@ -64,7 +63,7 b' impl Config {' | |||||
64 | ConfigSource::AbsPath(c) => { |
|
63 | ConfigSource::AbsPath(c) => { | |
65 | // TODO check if it should be trusted |
|
64 | // TODO check if it should be trusted | |
66 | // mercurial/ui.py:427 |
|
65 | // mercurial/ui.py:427 | |
67 |
let data = match read |
|
66 | let data = match std::fs::read(&c) { | |
68 | Err(_) => continue, // same as the python code |
|
67 | Err(_) => continue, // same as the python code | |
69 | Ok(data) => data, |
|
68 | Ok(data) => data, | |
70 | }; |
|
69 | }; |
@@ -8,9 +8,7 b'' | |||||
8 | // GNU General Public License version 2 or any later version. |
|
8 | // GNU General Public License version 2 or any later version. | |
9 |
|
9 | |||
10 | use crate::errors::{HgError, IoResultExt}; |
|
10 | use crate::errors::{HgError, IoResultExt}; | |
11 | use crate::utils::files::{ |
|
11 | use crate::utils::files::{get_bytes_from_path, get_path_from_bytes}; | |
12 | get_bytes_from_path, get_path_from_bytes, read_whole_file, |
|
|||
13 | }; |
|
|||
14 | use format_bytes::format_bytes; |
|
12 | use format_bytes::format_bytes; | |
15 | use lazy_static::lazy_static; |
|
13 | use lazy_static::lazy_static; | |
16 | use regex::bytes::Regex; |
|
14 | use regex::bytes::Regex; | |
@@ -244,10 +242,10 b' fn read_include(' | |||||
244 | new_src: &Path, |
|
242 | new_src: &Path, | |
245 | ) -> (PathBuf, io::Result<Vec<u8>>) { |
|
243 | ) -> (PathBuf, io::Result<Vec<u8>>) { | |
246 | if new_src.is_absolute() { |
|
244 | if new_src.is_absolute() { | |
247 |
(new_src.to_path_buf(), read |
|
245 | (new_src.to_path_buf(), std::fs::read(&new_src)) | |
248 | } else { |
|
246 | } else { | |
249 | let dir = old_src.parent().unwrap(); |
|
247 | let dir = old_src.parent().unwrap(); | |
250 | let new_src = dir.join(&new_src); |
|
248 | let new_src = dir.join(&new_src); | |
251 |
(new_src.to_owned(), read |
|
249 | (new_src.to_owned(), std::fs::read(&new_src)) | |
252 | } |
|
250 | } | |
253 | } |
|
251 | } |
@@ -18,7 +18,6 b' use lazy_static::lazy_static;' | |||||
18 | use same_file::is_same_file; |
|
18 | use same_file::is_same_file; | |
19 | use std::borrow::{Cow, ToOwned}; |
|
19 | use std::borrow::{Cow, ToOwned}; | |
20 | use std::fs::Metadata; |
|
20 | use std::fs::Metadata; | |
21 | use std::io::Read; |
|
|||
22 | use std::iter::FusedIterator; |
|
21 | use std::iter::FusedIterator; | |
23 | use std::ops::Deref; |
|
22 | use std::ops::Deref; | |
24 | use std::path::{Path, PathBuf}; |
|
23 | use std::path::{Path, PathBuf}; | |
@@ -309,17 +308,6 b' pub fn relativize_path(path: &HgPath, cw' | |||||
309 | } |
|
308 | } | |
310 | } |
|
309 | } | |
311 |
|
310 | |||
312 | /// Reads a file in one big chunk instead of doing multiple reads |
|
|||
313 | pub fn read_whole_file(filepath: &Path) -> std::io::Result<Vec<u8>> { |
|
|||
314 | let mut file = std::fs::File::open(filepath)?; |
|
|||
315 | let size = file.metadata()?.len(); |
|
|||
316 |
|
||||
317 | let mut res = vec![0; size as usize]; |
|
|||
318 | file.read_exact(&mut res)?; |
|
|||
319 |
|
||||
320 | Ok(res) |
|
|||
321 | } |
|
|||
322 |
|
||||
323 | #[cfg(test)] |
|
311 | #[cfg(test)] | |
324 | mod tests { |
|
312 | mod tests { | |
325 | use super::*; |
|
313 | use super::*; |
General Comments 0
You need to be logged in to leave comments.
Login now