[Updated] D9959: rust: replace read_whole_file with std::fs::read
SimonSapin
phabricator at mercurial-scm.org
Wed Feb 10 13:08:06 UTC 2021
Closed by commit rHG0d734c0ae1cf: rust: replace read_whole_file with std::fs::read (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D9959?vs=25489&id=25526
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D9959/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D9959
AFFECTED FILES
rust/hg-core/src/config/config.rs
rust/hg-core/src/config/layer.rs
rust/hg-core/src/utils/files.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/utils/files.rs b/rust/hg-core/src/utils/files.rs
--- a/rust/hg-core/src/utils/files.rs
+++ b/rust/hg-core/src/utils/files.rs
@@ -18,7 +18,6 @@
use same_file::is_same_file;
use std::borrow::{Cow, ToOwned};
use std::fs::Metadata;
-use std::io::Read;
use std::iter::FusedIterator;
use std::ops::Deref;
use std::path::{Path, PathBuf};
@@ -309,17 +308,6 @@
}
}
-/// Reads a file in one big chunk instead of doing multiple reads
-pub fn read_whole_file(filepath: &Path) -> std::io::Result<Vec<u8>> {
- let mut file = std::fs::File::open(filepath)?;
- let size = file.metadata()?.len();
-
- let mut res = vec![0; size as usize];
- file.read_exact(&mut res)?;
-
- Ok(res)
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rust/hg-core/src/config/layer.rs b/rust/hg-core/src/config/layer.rs
--- a/rust/hg-core/src/config/layer.rs
+++ b/rust/hg-core/src/config/layer.rs
@@ -8,9 +8,7 @@
// GNU General Public License version 2 or any later version.
use crate::errors::{HgError, IoResultExt};
-use crate::utils::files::{
- get_bytes_from_path, get_path_from_bytes, read_whole_file,
-};
+use crate::utils::files::{get_bytes_from_path, get_path_from_bytes};
use format_bytes::format_bytes;
use lazy_static::lazy_static;
use regex::bytes::Regex;
@@ -244,10 +242,10 @@
new_src: &Path,
) -> (PathBuf, io::Result<Vec<u8>>) {
if new_src.is_absolute() {
- (new_src.to_path_buf(), read_whole_file(&new_src))
+ (new_src.to_path_buf(), std::fs::read(&new_src))
} else {
let dir = old_src.parent().unwrap();
let new_src = dir.join(&new_src);
- (new_src.to_owned(), read_whole_file(&new_src))
+ (new_src.to_owned(), std::fs::read(&new_src))
}
}
diff --git a/rust/hg-core/src/config/config.rs b/rust/hg-core/src/config/config.rs
--- a/rust/hg-core/src/config/config.rs
+++ b/rust/hg-core/src/config/config.rs
@@ -14,7 +14,6 @@
use std::path::PathBuf;
use crate::repo::Repo;
-use crate::utils::files::read_whole_file;
/// Holds the config values for the current repository
/// TODO update this docstring once we support more sources
@@ -64,7 +63,7 @@
ConfigSource::AbsPath(c) => {
// TODO check if it should be trusted
// mercurial/ui.py:427
- let data = match read_whole_file(&c) {
+ let data = match std::fs::read(&c) {
Err(_) => continue, // same as the python code
Ok(data) => data,
};
To: SimonSapin, #hg-reviewers, Alphare, pulkit
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210210/0f73a265/attachment-0002.html>
More information about the Mercurial-patches
mailing list