From 737917e4218ccff5592f8ae6a4d5ce20ff330fdf Mon Sep 17 00:00:00 2001 From: mrbeanc Date: Thu, 21 Dec 2023 20:54:12 +0800 Subject: [PATCH] rustfmt: max-width=120 --- src/commands/commit.rs | 11 ++++------- src/head.rs | 3 +-- src/models/commit.rs | 6 +----- src/models/index.rs | 3 +-- src/models/tree.rs | 4 +--- src/rustfmt.toml | 2 +- src/utils/util.rs | 4 ++-- 7 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/commands/commit.rs b/src/commands/commit.rs index cf04fe7..0b9be98 100644 --- a/src/commands/commit.rs +++ b/src/commands/commit.rs @@ -17,8 +17,7 @@ pub fn commit(message: String, allow_empty: bool) { let current_head = head::current_head(); let current_commit_hash = head::current_head_commit(); - let mut commit = - commit::Commit::new(&index, vec![current_commit_hash.clone()], message.clone()); + let mut commit = commit::Commit::new(&index, vec![current_commit_hash.clone()], message.clone()); let commit_hash = commit.save(); head::update_head_commit(&commit_hash); @@ -26,11 +25,9 @@ pub fn commit(message: String, allow_empty: bool) { head::Head::Branch(branch_name) => { println!("commit to [{:?}] message{:?}", branch_name, message) } - head::Head::Detached(commit_hash) => println!( - "Detached HEAD commit {:?} message{:?}", - commit_hash[0..7].to_string(), - message - ), + head::Head::Detached(commit_hash) => { + println!("Detached HEAD commit {:?} message{:?}", commit_hash[0..7].to_string(), message) + } } println!("commit hash: {:?}", commit_hash); diff --git a/src/head.rs b/src/head.rs index 84fba17..cd11958 100644 --- a/src/head.rs +++ b/src/head.rs @@ -25,8 +25,7 @@ fn update_branch_head(branch_name: &String, commit_hash: &String) { branch.push("refs"); branch.push("heads"); branch.push(branch_name); - std::fs::write(&branch, commit_hash) - .expect(&format!("无法写入branch in {:?} with {}", branch, commit_hash)); + std::fs::write(&branch, commit_hash).expect(&format!("无法写入branch in {:?} with {}", branch, commit_hash)); } fn get_branch_head(branch_name: &String) -> String { diff --git a/src/models/commit.rs b/src/models/commit.rs index d55e461..38ec585 100644 --- a/src/models/commit.rs +++ b/src/models/commit.rs @@ -82,11 +82,7 @@ mod test { util::setup_test_with_mit(); let index = super::Index::new(); - let mut commit = super::Commit::new( - &index, - vec!["123".to_string(), "456".to_string()], - "test".to_string(), - ); + let mut commit = super::Commit::new(&index, vec!["123".to_string(), "456".to_string()], "test".to_string()); assert!(commit.hash.len() == 0); let hash = commit.save(); diff --git a/src/models/index.rs b/src/models/index.rs index 461a63a..adb34b8 100644 --- a/src/models/index.rs +++ b/src/models/index.rs @@ -128,8 +128,7 @@ impl Index { let path = Index::get_path(); if path.exists() { let json = fs::read_to_string(path).expect("无法读取index"); - let relative_index: HashMap = - serde_json::from_str(&json).expect("无法解析index"); + let relative_index: HashMap = serde_json::from_str(&json).expect("无法解析index"); self.entries = relative_index .into_iter() .map(|(path, value)| { diff --git a/src/models/tree.rs b/src/models/tree.rs index 6f8fe39..acc93e3 100644 --- a/src/models/tree.rs +++ b/src/models/tree.rs @@ -145,9 +145,7 @@ impl Tree { blob_hashs.append( sub_blobs .iter() - .map(|(path, blob_hash)| { - (PathBuf::from(entry.name.clone()).join(path), blob_hash.clone()) - }) + .map(|(path, blob_hash)| (PathBuf::from(entry.name.clone()).join(path), blob_hash.clone())) .collect::>() .as_mut(), ); diff --git a/src/rustfmt.toml b/src/rustfmt.toml index 608dcd4..e9e2b27 100644 --- a/src/rustfmt.toml +++ b/src/rustfmt.toml @@ -1,7 +1,7 @@ # Run rustfmt with this config (it should be picked up automatically). version = "Two" use_small_heuristics = "Max" -max_width = 100 +max_width = 120 struct_lit_width = 60 chain_width = 60 single_line_if_else_max_width = 60 diff --git a/src/utils/util.rs b/src/utils/util.rs index 4dcda84..d2b8afa 100644 --- a/src/utils/util.rs +++ b/src/utils/util.rs @@ -61,8 +61,8 @@ pub fn setup_test_without_mit() { pub fn ensure_test_file(path: &Path, content: option::Option<&str>) { // 以测试目录为根目录,创建文件 - let mut file = fs::File::create(get_working_dir().unwrap().join(path)) - .expect(format!("无法创建文件:{:?}", path).as_str()); + let mut file = + fs::File::create(get_working_dir().unwrap().join(path)).expect(format!("无法创建文件:{:?}", path).as_str()); if let Some(content) = content { file.write(content.as_bytes()).unwrap(); } else {