diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 674f706..f9cf21c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,9 +1,9 @@ pub mod add; +pub mod branch; pub mod commit; pub mod init; -pub mod remove; -pub mod status; pub mod log; -pub mod branch; +pub mod remove; +pub mod restore; +pub mod status; pub mod switch; -pub mod restore; \ No newline at end of file diff --git a/src/commands/restore.rs b/src/commands/restore.rs index e69de29..8b13789 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -0,0 +1 @@ + diff --git a/src/head.rs b/src/head.rs index 129c79f..a7f7ce9 100644 --- a/src/head.rs +++ b/src/head.rs @@ -8,10 +8,7 @@ pub enum Head { pub fn current_head() -> Head { let mut head = util::get_storage_path().unwrap(); head.push("HEAD"); - let head_content = std::fs::read_to_string(head) - .expect("HEAD文件损坏") - .trim_end() - .to_string(); //去除末尾\n + let head_content = std::fs::read_to_string(head).expect("HEAD文件损坏").trim_end().to_string(); //去除末尾\n if head_content.starts_with("ref: refs/heads/") { let branch_name = head_content.trim_start_matches("ref: refs/heads/"); Head::Branch(branch_name.to_string()) @@ -53,7 +50,7 @@ pub fn delete_branch(branch_name: &String) { } } -/**返回当前head指向的commit hash,如果是分支,则返回分支的commit hash*/ +/**返回当前head指向的commit hash,如果是分支,则返回分支的commit hash */ pub fn current_head_commit() -> String { let head = current_head(); match head { @@ -65,7 +62,7 @@ pub fn current_head_commit() -> String { } } -/** 将当前的head指向commit_hash,根据当前的head类型,更新不同的文件 */ +/** 将当前的head指向commit_hash,根据当前的head类型,更新不同的文件 */ pub fn update_head_commit(commit_hash: &String) { let head = current_head(); match head { diff --git a/src/models/tree.rs b/src/models/tree.rs index 756c535..a20f18f 100644 --- a/src/models/tree.rs +++ b/src/models/tree.rs @@ -52,17 +52,8 @@ fn store_path_to_tree(path_entries: &Vec, current_root: PathBuf) -> Tre continue; } // 拿到下一级别目录 - let process_path = path - .components() - .nth(0) - .unwrap() - .as_os_str() - .to_str() - .unwrap(); - if processed_path - .insert(process_path.to_string(), true) - .is_some() - { + let process_path = path.components().nth(0).unwrap().as_os_str().to_str().unwrap(); + if processed_path.insert(process_path.to_string(), true).is_some() { continue; } diff --git a/src/store.rs b/src/store.rs index 265d465..9e4f260 100644 --- a/src/store.rs +++ b/src/store.rs @@ -32,7 +32,7 @@ impl Store { path.exists() } - /** 根据前缀搜索,有歧义时返回 None*/ + /** 根据前缀搜索,有歧义时返回 None */ pub fn search(&self, hash: &String) -> Option { if hash.is_empty() { return None;