mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-29 05:09:47 +08:00
优化add逻辑
This commit is contained in:
@@ -50,13 +50,17 @@ fn add_a_file(file: &Path, index: &mut Index) {
|
||||
println!("add a file: {}", get_relative_path(file, get_working_dir().unwrap()).display());
|
||||
if !file.exists() { //文件被删除
|
||||
index.remove(file);
|
||||
} else {
|
||||
let blob = Blob::new(file);
|
||||
let file_data = FileMetaData::new(&blob, file);
|
||||
} else { //文件存在
|
||||
if !index.contains(file) { //文件未被跟踪
|
||||
index.add(file.to_path_buf(), file_data);
|
||||
let blob = Blob::new(file);
|
||||
index.add(file.to_path_buf(), FileMetaData::new(&blob, file));
|
||||
} else { //文件已被跟踪,可能被修改
|
||||
index.update(file.to_path_buf(), file_data);
|
||||
if index.is_modified(file) { //文件被修改,但不一定内容更改
|
||||
let blob = Blob::new(file); //到这一步才创建blob是为了优化
|
||||
if !index.verify_hash(file, &blob.get_hash()) { //比较hash 确认内容更改
|
||||
index.update(file.to_path_buf(), FileMetaData::new(&blob, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user