mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-14 02:07:22 +03:00
cleanup: use fs:read()
instead of File::open().read_to_end()
This commit is contained in:
parent
b8cc6fc3c8
commit
e414f3b73c
@ -24,7 +24,7 @@ use std::io::{Read, Write};
|
||||
use std::ops::Range;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::{io, iter};
|
||||
use std::{fs, io, iter};
|
||||
|
||||
use blake2::Blake2b512;
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@ -86,11 +86,7 @@ impl DefaultIndexStore {
|
||||
op_id: &OperationId,
|
||||
) -> Result<Arc<ReadonlyIndexImpl>, IndexLoadError> {
|
||||
let op_id_file = self.dir.join("operations").join(op_id.hex());
|
||||
let mut buf = vec![];
|
||||
File::open(op_id_file)
|
||||
.unwrap()
|
||||
.read_to_end(&mut buf)
|
||||
.unwrap();
|
||||
let buf = fs::read(op_id_file).unwrap();
|
||||
let index_file_id_hex = String::from_utf8(buf).unwrap();
|
||||
let index_file_path = self.dir.join(&index_file_id_hex);
|
||||
let mut index_file = File::open(index_file_path).unwrap();
|
||||
|
@ -14,8 +14,7 @@
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -184,9 +183,7 @@ impl GitIgnoreFile {
|
||||
file: PathBuf,
|
||||
) -> Arc<GitIgnoreFile> {
|
||||
if file.is_file() {
|
||||
let mut file = File::open(file).unwrap();
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
let buf = fs::read(file).unwrap();
|
||||
self.chain(prefix, &buf)
|
||||
} else {
|
||||
self.clone()
|
||||
|
@ -161,9 +161,7 @@ impl Backend for LocalBackend {
|
||||
|
||||
fn read_symlink(&self, _path: &RepoPath, id: &SymlinkId) -> Result<String, BackendError> {
|
||||
let path = self.symlink_path(id);
|
||||
let mut file = File::open(path).map_err(|err| map_not_found_err(err, id))?;
|
||||
let mut target = String::new();
|
||||
file.read_to_string(&mut target).unwrap();
|
||||
let target = fs::read_to_string(path).map_err(|err| map_not_found_err(err, id))?;
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
|
@ -975,16 +975,10 @@ impl TreeState {
|
||||
if let Some(TreeValue::Conflict(conflict_id)) = ¤t_tree_value {
|
||||
let conflict = self.store.read_conflict(repo_path, conflict_id)?;
|
||||
if let Some(old_file_ids) = conflict.to_file_merge() {
|
||||
let mut file = File::open(disk_path).map_err(|err| SnapshotError::IoError {
|
||||
let content = fs::read(disk_path).map_err(|err| SnapshotError::IoError {
|
||||
message: format!("Failed to open file {}", disk_path.display()),
|
||||
err,
|
||||
})?;
|
||||
let mut content = vec![];
|
||||
file.read_to_end(&mut content)
|
||||
.map_err(|err| SnapshotError::IoError {
|
||||
message: format!("Failed to read file {}", disk_path.display()),
|
||||
err,
|
||||
})?;
|
||||
let new_file_ids = conflicts::update_from_content(
|
||||
&old_file_ids,
|
||||
self.store.as_ref(),
|
||||
|
@ -14,8 +14,9 @@
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -304,9 +305,7 @@ impl WorkspaceLoader {
|
||||
// If .jj/repo is a file, then we interpret its contents as a relative path to
|
||||
// the actual repo directory (typically in another workspace).
|
||||
if repo_dir.is_file() {
|
||||
let mut repo_file = File::open(&repo_dir).context(&repo_dir)?;
|
||||
let mut buf = Vec::new();
|
||||
repo_file.read_to_end(&mut buf).context(&repo_dir)?;
|
||||
let buf = fs::read(&repo_dir).context(&repo_dir)?;
|
||||
let repo_path_str =
|
||||
String::from_utf8(buf).map_err(|_| WorkspaceLoadError::NonUnicodePath)?;
|
||||
repo_dir = jj_dir
|
||||
|
Loading…
Reference in New Issue
Block a user