mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-05-01 06:09:59 +08:00
临时提交:add & index & blob
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use colored::Colorize;
|
||||
use crate::models::index::Index;
|
||||
use crate::utils::util::{check_repo_exist, get_working_dir, list_files};
|
||||
use crate::models::blob::Blob;
|
||||
use crate::models::index::{FileMetaData, Index};
|
||||
use crate::utils::util::{check_repo_exist, get_file_mode, get_relative_path, get_working_dir, list_files};
|
||||
|
||||
pub fn add(files: Vec<String>, all: bool, mut update: bool) {
|
||||
check_repo_exist();
|
||||
let index = Index::new();
|
||||
let mut index = Index::new();
|
||||
let mut dot = files.contains(&".".to_string());
|
||||
|
||||
let mut files: Vec<PathBuf> = files.into_iter().map(PathBuf::from).collect();
|
||||
@@ -33,13 +34,30 @@ pub fn add(files: Vec<String>, all: bool, mut update: bool) {
|
||||
index.contains(file)
|
||||
});
|
||||
}
|
||||
|
||||
files.extend(index.get_deleted_files()); //包含已删除的文件
|
||||
}
|
||||
|
||||
for file in files {
|
||||
add_a_file(file.as_path(), &index);
|
||||
for file in &files {
|
||||
add_a_file(file, &mut index);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_a_file(file: &Path, index: &Index) {
|
||||
println!("add a file: {:?}", file);
|
||||
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 if !index.contains(file) { //文件未被跟踪
|
||||
let blob = Blob::new(file);
|
||||
let meta = file.metadata().unwrap();
|
||||
index.add(file.to_path_buf(), FileMetaData{
|
||||
hash: blob.get_hash(),
|
||||
size: meta.len(),
|
||||
created_time: meta.created().unwrap(),
|
||||
modified_time: meta.modified().unwrap(),
|
||||
mode: get_file_mode(file)
|
||||
});
|
||||
} else { //文件已被跟踪,可能被修改
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user