mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-25 11:21:44 +08:00
简化Blob::restore调用
This commit is contained in:
@@ -75,7 +75,7 @@ pub fn restore_worktree(filter: Option<&Vec<PathBuf>>, target_blobs: &Vec<(PathB
|
||||
//文件不存在于workdir
|
||||
if target_blobs.contains_key(path) {
|
||||
//文件存在于target_commit (deleted),需要恢复
|
||||
Blob::load(&target_blobs[path]).restore(&path);
|
||||
Blob::restore(&target_blobs[path], &path);
|
||||
} else {
|
||||
//在target_commit和workdir中都不存在(非法路径), 用户输入
|
||||
println!("fatal: pathspec '{}' did not match any files", path.display());
|
||||
@@ -86,7 +86,7 @@ pub fn restore_worktree(filter: Option<&Vec<PathBuf>>, target_blobs: &Vec<(PathB
|
||||
//文件已修改(modified)
|
||||
let file_hash = util::calc_file_hash(&path); //TODO tree没有存修改时间,所以这里只能用hash判断
|
||||
if file_hash != target_blobs[path] {
|
||||
Blob::load(&target_blobs[path]).restore(&path);
|
||||
Blob::restore(&target_blobs[path], &path);
|
||||
}
|
||||
} else {
|
||||
//新文件,也分两种情况:1.已跟踪,需要删除 2.未跟踪,保留
|
||||
|
||||
@@ -24,18 +24,22 @@ impl Blob {
|
||||
}
|
||||
|
||||
/// 通过hash值加载blob(从/objects/)
|
||||
#[allow(dead_code)]
|
||||
pub fn load(hash: &String) -> Blob {
|
||||
pub fn load(hash: &Hash) -> Blob {
|
||||
let s = Store::new();
|
||||
let data = s.load(hash);
|
||||
Blob { hash: hash.clone(), data }
|
||||
}
|
||||
|
||||
///将hash对应的blob还原到file
|
||||
pub fn restore(&self, file: &Path) {
|
||||
///blob还原到file
|
||||
pub fn restore_to_file(&self, file: &Path) {
|
||||
util::write(file, &self.data).unwrap();
|
||||
}
|
||||
|
||||
/// 将hash对应的blob还原到file, static方法,对[Blob::restore_to_file]的封装
|
||||
pub fn restore(hash: &Hash, file: &Path) {
|
||||
Blob::load(hash).restore_to_file(file);
|
||||
}
|
||||
|
||||
/// 写入文件;优化:文件已存在时不做操作
|
||||
pub fn save(&self) {
|
||||
let s = Store::new();
|
||||
|
||||
Reference in New Issue
Block a user