From 5c439aeff2dc4b0c2409a9a07d13bda7985a7453 Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Fri, 22 Dec 2023 09:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0format=EF=BC=8C=E5=AF=B9use?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rustfmt.toml | 15 ++++++++++++--- src/cli.rs | 11 +++-------- src/commands/add.rs | 20 +++++++++++++------- src/commands/branch.rs | 3 +-- src/commands/commit.rs | 6 ++++-- src/commands/remove.rs | 10 +++++----- src/commands/status.rs | 11 ++++++----- src/models/blob.rs | 7 ++----- src/models/index.rs | 18 ++++++++++-------- src/models/tree.rs | 7 ++++--- src/utils/util.rs | 9 ++++++--- 11 files changed, 66 insertions(+), 51 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index dc9c3ee..d0a626d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -6,13 +6,22 @@ struct_lit_width = 60 chain_width = 80 single_line_if_else_max_width = 60 single_line_let_else_max_width = 60 - merge_derives = true reorder_imports = true + +unstable_features = true # 使能 unstable 特性 +## unstable features below ## # 格式化注释代码块:Unstable format_code_in_doc_comments = true - - +# 重新排序mod +reorder_modules = true +# 按照 crate 重新排序 +imports_granularity = "Crate" +# 过长换行使用大括号 +match_arm_blocks = true +# 数组换行 +indent_style = "Block" # 彩色输出:Unstable color = "Auto" +# 忽略,也是 unstable 特性 ignore = ["tests"] diff --git a/src/cli.rs b/src/cli.rs index d926092..b8b19ad 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,12 +1,7 @@ use clap::{ArgGroup, Parser, Subcommand}; -use mit::commands::add::add; -use mit::commands::branch::branch; -use mit::commands::commit::commit; -use mit::commands::init::init; -use mit::commands::log::log; -use mit::commands::remove::remove; -use mit::commands::status::status; -use mit::commands::switch::switch; +use mit::commands::{ + add::add, branch::branch, commit::commit, init::init, log::log, remove::remove, status::status, switch::switch, +}; /// Rust实现的简易版本的Git,用于学习Rust语言 #[derive(Parser)] diff --git a/src/commands/add.rs b/src/commands/add.rs index 6a4b54b..3211245 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -1,13 +1,19 @@ -use std::env; -use std::path::{Path, PathBuf}; +use std::{ + env, + path::{Path, PathBuf}, +}; use colored::Colorize; -use crate::models::blob::Blob; -use crate::models::index::{FileMetaData, Index}; -use crate::utils::util::{ - check_repo_exist, get_working_dir, is_inside_repo, is_inside_workdir, list_files, to_workdir_relative_path, - ROOT_DIR, +use crate::{ + models::{ + blob::Blob, + index::{FileMetaData, Index}, + }, + utils::util::{ + check_repo_exist, get_working_dir, is_inside_repo, is_inside_workdir, list_files, to_workdir_relative_path, + ROOT_DIR, + }, }; pub fn add(files: Vec, all: bool, mut update: bool) { diff --git a/src/commands/branch.rs b/src/commands/branch.rs index 985abd0..e096839 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -127,8 +127,7 @@ pub fn branch( #[cfg(test)] mod test { use super::*; - use crate::commands; - use crate::utils::util; + use crate::{commands, utils::util}; #[test] fn test_create_branch() { util::setup_test_with_clean_mit(); diff --git a/src/commands/commit.rs b/src/commands/commit.rs index 498fe16..b66fddd 100644 --- a/src/commands/commit.rs +++ b/src/commands/commit.rs @@ -1,5 +1,7 @@ -use crate::head; -use crate::models::{commit, index}; +use crate::{ + head, + models::{commit, index}, +}; use super::status; diff --git a/src/commands/remove.rs b/src/commands/remove.rs index b2b16d0..d3d5034 100644 --- a/src/commands/remove.rs +++ b/src/commands/remove.rs @@ -1,9 +1,9 @@ -use crate::models::index::Index; -use crate::utils::util; -use crate::utils::util::check_repo_exist; +use crate::{ + models::index::Index, + utils::{util, util::check_repo_exist}, +}; use colored::Colorize; -use std::path::PathBuf; -use std::{fs, io}; +use std::{fs, io, path::PathBuf}; /// 从暂存区&|工作区删除文件 pub fn remove(files: Vec, cached: bool, recursive: bool) -> io::Result<()> { diff --git a/src/commands/status.rs b/src/commands/status.rs index 74622cc..de7e5fa 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -1,8 +1,9 @@ -use crate::head::Head; -use crate::models::commit::Commit; -use crate::models::index::Index; -use crate::utils::util::check_repo_exist; -use crate::{head, utils::util}; +use crate::{ + head, + head::Head, + models::{commit::Commit, index::Index}, + utils::{util, util::check_repo_exist}, +}; use colored::Colorize; use std::path::PathBuf; diff --git a/src/models/blob.rs b/src/models/blob.rs index e24f566..68c2511 100644 --- a/src/models/blob.rs +++ b/src/models/blob.rs @@ -1,8 +1,5 @@ -use crate::models::object::Hash; -use crate::store::Store; -use crate::utils::util::calc_hash; -use std::fs; -use std::path::Path; +use crate::{models::object::Hash, store::Store, utils::util::calc_hash}; +use std::{fs, path::Path}; /** Blob diff --git a/src/models/index.rs b/src/models/index.rs index 5cb055c..9d88db1 100644 --- a/src/models/index.rs +++ b/src/models/index.rs @@ -1,12 +1,14 @@ -use crate::models::blob::Blob; -use crate::models::object::Hash; -use crate::utils::util; -use crate::utils::util::get_relative_path; +use crate::{ + models::{blob::Blob, object::Hash}, + utils::{util, util::get_relative_path}, +}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::fs; -use std::path::{Path, PathBuf}; -use std::time::SystemTime; +use std::{ + collections::HashMap, + fs, + path::{Path, PathBuf}, + time::SystemTime, +}; // 文件元数据结构 #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/models/tree.rs b/src/models/tree.rs index a20f18f..7149804 100644 --- a/src/models/tree.rs +++ b/src/models/tree.rs @@ -150,9 +150,10 @@ impl Tree { mod test { use std::path::PathBuf; - use crate::models::blob::Blob; - use crate::models::index::FileMetaData; - use crate::utils::util; + use crate::{ + models::{blob::Blob, index::FileMetaData}, + utils::util, + }; #[test] fn test_new() { util::setup_test_with_clean_mit(); diff --git a/src/utils/util.rs b/src/utils/util.rs index 1827ee9..6e85b98 100644 --- a/src/utils/util.rs +++ b/src/utils/util.rs @@ -1,7 +1,10 @@ use sha1::{Digest, Sha1}; -use std::io::Write; -use std::path::{Path, PathBuf}; -use std::{fs, io, option}; +use std::{ + fs, io, + io::Write, + option, + path::{Path, PathBuf}, +}; pub const ROOT_DIR: &str = ".mit"; pub const TEST_DIR: &str = "mit_test_storage"; // 执行测试的储存库