From 43bbe0dd48ec8750c2474ed607d6342da4436c8d Mon Sep 17 00:00:00 2001 From: Quanyi Ma Date: Wed, 5 Jun 2024 18:00:26 +0800 Subject: [PATCH 1/4] Remove the scoprpio from workspace Signed-off-by: Quanyi Ma --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 854fedc92..7cd113a27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "venus", "ceres", "libra", - "scorpio", ] exclude = ["craft"] resolver = "1" From 09082576741c73ac028d435e8ef30044f5e7f05a Mon Sep 17 00:00:00 2001 From: Quanyi Ma Date: Wed, 5 Jun 2024 19:15:06 +0800 Subject: [PATCH 2/4] Fix the comments of codes Signed-off-by: Quanyi Ma --- libra/src/command/add.rs | 6 +++--- libra/src/command/branch.rs | 2 +- mercury/src/internal/pack/cache.rs | 2 +- mercury/src/internal/pack/cache_object.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libra/src/command/add.rs b/libra/src/command/add.rs index ec40740a6..fd032340c 100644 --- a/libra/src/command/add.rs +++ b/libra/src/command/add.rs @@ -9,13 +9,13 @@ use crate::utils::{path, util}; #[derive(Parser, Debug)] pub struct AddArgs { - /// ... files & dir to add content from. + /// pathspec... files & dir to add content from. #[clap(required = false)] pub pathspec: Vec, - /// Update the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree. + /// Update the index not only where the working tree has a file matching pathspec but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree. /// - /// If no is given when -A option is used, all files in the entire working tree are updated + /// If no pathspec is given when -A option is used, all files in the entire working tree are updated #[clap(short = 'A', long, group = "mode")] pub all: bool, diff --git a/libra/src/command/branch.rs b/libra/src/command/branch.rs index 620511dfe..95a7908f5 100644 --- a/libra/src/command/branch.rs +++ b/libra/src/command/branch.rs @@ -26,7 +26,7 @@ pub struct BranchArgs { #[clap(short = 'D', long, group = "sub")] delete: Option, - /// Set up 's tracking information + /// Set up current branch's tracking information #[clap(short = 'u', long, group = "sub")] set_upstream_to: Option, diff --git a/mercury/src/internal/pack/cache.rs b/mercury/src/internal/pack/cache.rs index 33e4a07ce..b14f7a934 100644 --- a/mercury/src/internal/pack/cache.rs +++ b/mercury/src/internal/pack/cache.rs @@ -103,7 +103,7 @@ impl Caches { self.pool.queued_count() } - /// memory used by the index (exclude lru_cache which is contained in [CacheObject::get_mem_size()]) + /// memory used by the index (exclude lru_cache which is contained in CacheObject::get_mem_size()) pub fn memory_used_index(&self) -> usize { self.map_offset.capacity() * (std::mem::size_of::() + std::mem::size_of::()) + self.hash_set.capacity() * (std::mem::size_of::()) diff --git a/mercury/src/internal/pack/cache_object.rs b/mercury/src/internal/pack/cache_object.rs index 626ab5830..7ecc7badc 100644 --- a/mercury/src/internal/pack/cache_object.rs +++ b/mercury/src/internal/pack/cache_object.rs @@ -180,9 +180,9 @@ pub trait ArcWrapperBounds: HeapSize + Serialize + for<'a> Deserialize<'a> + Sen // Or, `T` will not satisfy `Alias Trait` even if it satisfies the Original traits impl Deserialize<'a> + Send + Sync + 'static> ArcWrapperBounds for T {} -/// !Implementing encapsulation of Arc to enable third-party Trait HeapSize implementation for the Arc type -/// !Because of use Arc in LruCache, the LruCache is not clear whether a pointer will drop the referenced -/// ! content when it is ejected from the cache, the actual memory usage is not accurate +/// Implementing encapsulation of Arc to enable third-party Trait HeapSize implementation for the Arc type +/// Because of use Arc in LruCache, the LruCache is not clear whether a pointer will drop the referenced +/// content when it is ejected from the cache, the actual memory usage is not accurate pub struct ArcWrapper { pub data: Arc, complete_signal: Arc, From 966b6f3bf4c6f48228013f1d9579fbe14b365bf8 Mon Sep 17 00:00:00 2001 From: Quanyi Ma Date: Wed, 5 Jun 2024 19:35:54 +0800 Subject: [PATCH 3/4] Fix typos Signed-off-by: Quanyi Ma --- libra/src/command/branch.rs | 22 +++++++++++----------- mercury/src/internal/pack/cache.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libra/src/command/branch.rs b/libra/src/command/branch.rs index 95a7908f5..56aeea33b 100644 --- a/libra/src/command/branch.rs +++ b/libra/src/command/branch.rs @@ -187,23 +187,23 @@ async fn list_branches(remotes: bool) { } pub async fn get_target_commit(branch_or_commit: &str) -> Result> { - let posible_branchs = Branch::search_branch(branch_or_commit).await; - if posible_branchs.len() > 1 { + let possible_branches = Branch::search_branch(branch_or_commit).await; + if possible_branches.len() > 1 { return Err("fatal: Ambiguous branch name".into()); // TODO: git have a priority list of branches to use, continue with ambiguity, we didn't implement it yet } - if posible_branchs.is_empty() { + if possible_branches.is_empty() { let storage = ClientStorage::init(utils::path::objects()); - let posible_commits = storage.search(branch_or_commit); - if posible_commits.len() > 1 || posible_commits.is_empty() { + let possible_commits = storage.search(branch_or_commit); + if possible_commits.len() > 1 || possible_commits.is_empty() { return Err( format!("fatal: {} is not something we can merge", branch_or_commit).into(), ); } - Ok(posible_commits[0]) + Ok(possible_commits[0]) } else { - Ok(posible_branchs[0].commit) + Ok(possible_branches[0].commit) } } @@ -289,8 +289,8 @@ mod tests { }; let first_branch = Branch::find_branch(&first_branch_name, None).await.unwrap(); - assert!(first_branch.commit == first_commit_id); - assert!(first_branch.name == first_branch_name); + assert_eq!(first_branch.commit, first_commit_id); + assert_eq!(first_branch.name, first_branch_name); } { @@ -309,8 +309,8 @@ mod tests { let second_branch = Branch::find_branch(&second_branch_name, None) .await .unwrap(); - assert!(second_branch.commit == second_commit_id); - assert!(second_branch.name == second_branch_name); + assert_eq!(second_branch.commit, second_commit_id); + assert_eq!(second_branch.name, second_branch_name); } // show current branch diff --git a/mercury/src/internal/pack/cache.rs b/mercury/src/internal/pack/cache.rs index b14f7a934..7c4c1323b 100644 --- a/mercury/src/internal/pack/cache.rs +++ b/mercury/src/internal/pack/cache.rs @@ -225,7 +225,7 @@ mod test { use crate::hash::SHA1; #[test] - fn test_cach_single_thread() { + fn test_cache_single_thread() { let source = PathBuf::from(env::current_dir().unwrap().parent().unwrap()); let cache = Caches::new(Some(2048), source.clone().join("tests/.cache_tmp"), 1); let a = CacheObject { From c9e44247bdbdf0615bee691ddb3b8cf9d2834b21 Mon Sep 17 00:00:00 2001 From: Quanyi Ma Date: Thu, 6 Jun 2024 00:04:59 +0800 Subject: [PATCH 4/4] Fix typos Signed-off-by: Quanyi Ma --- libra/src/command/commit.rs | 14 +++--- libra/src/command/index_pack.rs | 10 ++--- libra/src/command/merge.rs | 8 ++-- libra/src/internal/config.rs | 4 +- libra/src/internal/db.rs | 6 +-- libra/src/internal/protocol/https_client.rs | 2 +- libra/src/utils/path_ext.rs | 4 +- libra/src/utils/test.rs | 48 --------------------- libra/src/utils/util.rs | 5 +-- mercury/src/internal/pack/cache.rs | 2 +- 10 files changed, 27 insertions(+), 76 deletions(-) diff --git a/libra/src/command/commit.rs b/libra/src/command/commit.rs index a1a524377..b87888c46 100644 --- a/libra/src/command/commit.rs +++ b/libra/src/command/commit.rs @@ -178,7 +178,7 @@ mod test { if item.name == "DeveloperExperience" { let sub_tree = storage.get(&item.id).unwrap(); let tree = Tree::from_bytes(&sub_tree, item.id).unwrap(); - assert!(tree.tree_items.len() == 4); // 4 sub tree according to the test data + assert_eq!(tree.tree_items.len(), 4); // 4 subtree according to the test data } } } @@ -186,7 +186,7 @@ mod test { #[tokio::test] #[should_panic] - async fn test_excute_commit_with_empty_index_fail() { + async fn test_execute_commit_with_empty_index_fail() { test::setup_with_new_libra().await; let args = CommitArgs { message: "init".to_string(), @@ -215,9 +215,9 @@ mod test { let branch = Branch::find_branch(&branch_name, None).await.unwrap(); let commit: Commit = load_object(&branch.commit).unwrap(); - assert!(commit.message == "init"); + assert_eq!(commit.message, "init"); let branch = Branch::find_branch(&branch_name, None).await.unwrap(); - assert!(branch.commit == commit.id); + assert_eq!(branch.commit, commit.id); } // create a new commit @@ -244,15 +244,15 @@ mod test { let commit_id = Head::current_commit().await.unwrap(); let commit: Commit = load_object(&commit_id).unwrap(); - assert!(commit.message == "add some files", "{}", commit.message); + assert_eq!(commit.message, "add some files", "{}", commit.message); let pre_commit_id = commit.parent_commit_ids[0]; let pre_commit: Commit = load_object(&pre_commit_id).unwrap(); - assert!(pre_commit.message == "init"); + assert_eq!(pre_commit.message, "init"); let tree_id = commit.tree_id; let tree: Tree = load_object(&tree_id).unwrap(); - assert!(tree.tree_items.len() == 2); // 2 sub tree according to the test data + assert_eq!(tree.tree_items.len(), 2); // 2 subtree according to the test data } } } diff --git a/libra/src/command/index_pack.rs b/libra/src/command/index_pack.rs index 6644f59a3..8aa51e20c 100644 --- a/libra/src/command/index_pack.rs +++ b/libra/src/command/index_pack.rs @@ -78,26 +78,26 @@ pub fn build_index_v1(pack_file: &str, index_file: &str) -> Result<(), GitError> // This is called the first-level fan-out table. let mut i: u8 = 0; let mut cnt: u32 = 0; - let mut fanout = Vec::with_capacity(256 * 4); + let mut fan_out = Vec::with_capacity(256 * 4); let obj_map = Arc::try_unwrap(obj_map).unwrap().into_inner().unwrap(); for (hash, _) in obj_map.iter() { // sorted let first_byte = hash.0[0]; while first_byte > i { // `while` rather than `if` to fill the gap, e.g. 0, 1, 2, 2, 2, 6 - fanout.write_u32::(cnt)?; + fan_out.write_u32::(cnt)?; i += 1; } cnt += 1; } // fill the rest loop { - fanout.write_u32::(cnt)?; + fan_out.write_u32::(cnt)?; if i == 255 { break; } i += 1; } - index_hash.update(&fanout); - index_file.write_all(&fanout)?; + index_hash.update(&fan_out); + index_file.write_all(&fan_out)?; // 4-byte network byte order integer, recording where the // object is stored in the pack-file as the offset from the beginning. diff --git a/libra/src/command/merge.rs b/libra/src/command/merge.rs index ef1fe015f..fc1f53807 100644 --- a/libra/src/command/merge.rs +++ b/libra/src/command/merge.rs @@ -71,10 +71,10 @@ async fn lca_commit(lhs: &Commit, rhs: &Commit) -> Option { } } - for lhs_parrent in lhs_reachable.iter() { - for rhs_parrent in rhs_reachable.iter() { - if lhs_parrent.id == rhs_parrent.id { - return Some(lhs_parrent.to_owned()); + for lhs_parent in lhs_reachable.iter() { + for rhs_parent in rhs_reachable.iter() { + if lhs_parent.id == rhs_parent.id { + return Some(lhs_parent.to_owned()); } } } diff --git a/libra/src/internal/config.rs b/libra/src/internal/config.rs index 1cd737567..f45bf4a45 100644 --- a/libra/src/internal/config.rs +++ b/libra/src/internal/config.rs @@ -27,7 +27,7 @@ impl Config { // todo accept a db connect or a transaction from outside pub async fn insert(configuration: &str, name: Option<&str>, key: &str, value: &str) { let db = get_db_conn_instance().await; - let config = config::ActiveModel { + let config = ActiveModel { configuration: Set(configuration.to_owned()), name: Set(name.map(|s| s.to_owned())), key: Set(key.to_owned()), @@ -136,7 +136,7 @@ impl Config { if config_entries.is_empty() { None } else { - assert!(config_entries.len() == 2); + assert_eq!(config_entries.len(), 2); // if branch_config[0].key == "merge" { // Some(BranchConfig { // name: name.to_owned(), diff --git a/libra/src/internal/db.rs b/libra/src/internal/db.rs index 4b62dc13c..9338124a3 100644 --- a/libra/src/internal/db.rs +++ b/libra/src/internal/db.rs @@ -90,7 +90,7 @@ async fn setup_database_sql(conn: &DatabaseConnection) -> Result<(), Transaction /// Create a new SQLite database file at the specified path. /// **should only be called in init or test** /// - `db_path` is the path to the SQLite database file. -/// - Returns `Ok(())` if the database file was created and the schema was setup successfully. +/// - Returns `Ok(())` if the database file was created and the schema was set up successfully. /// - Returns an `IOError` if the database file already exists, or if there was an error creating the file or setting up the schema. #[allow(dead_code)] pub async fn create_database(db_path: &str) -> io::Result { @@ -108,7 +108,7 @@ pub async fn create_database(db_path: &str) -> io::Result { ) })?; - // Connect to the new database and setup the schema. + // Connect to the new database and set up the schema. if let Ok(conn) = establish_connection(db_path).await { setup_database_sql(&conn).await.map_err(|err| { IOError::new( @@ -146,7 +146,7 @@ mod tests { } impl TestDbPath { async fn new(name: &str) -> Self { - let mut db_path = PathBuf::from("/tmp/testdb"); + let mut db_path = PathBuf::from("/tmp/test_db"); if !db_path.exists() { let _ = fs::create_dir(&db_path); } diff --git a/libra/src/internal/protocol/https_client.rs b/libra/src/internal/protocol/https_client.rs index 3f66a39d3..f1c5995c6 100644 --- a/libra/src/internal/protocol/https_client.rs +++ b/libra/src/internal/protocol/https_client.rs @@ -133,7 +133,7 @@ impl HttpsClient { // for git-upload-pack, the first line is HEAD assert_eq!(head, "HEAD"); } - // ..default ref named HEAD as the first ref. The stream MUST include capability declarations behind a NUL on the first ref. + // default ref named HEAD as the first ref. The stream MUST include capability declarations behind a NUL on the first ref. ref_list.push(DiscoveredReference { _hash: hash.to_string(), _ref: head.to_string(), diff --git a/libra/src/utils/path_ext.rs b/libra/src/utils/path_ext.rs index 2f22f820b..d5c6cf1d1 100644 --- a/libra/src/utils/path_ext.rs +++ b/libra/src/utils/path_ext.rs @@ -5,9 +5,9 @@ pub trait PathExt { fn to_workdir(&self) -> PathBuf; fn to_string_or_panic(&self) -> String; fn workdir_to_absolute(&self) -> PathBuf; - #[allow(dead_code)] // @Qihang Cai + #[allow(dead_code)] fn workdir_to_current(&self) -> PathBuf; - #[allow(dead_code)] // @Qihang Cai + #[allow(dead_code)] fn sub_of(&self, parent: &Path) -> bool; fn sub_of_paths(&self, paths: U) -> bool where diff --git a/libra/src/utils/test.rs b/libra/src/utils/test.rs index 9c509807e..217642326 100644 --- a/libra/src/utils/test.rs +++ b/libra/src/utils/test.rs @@ -113,31 +113,6 @@ pub fn init_logger() { .unwrap(); } -// pub fn ensure_files>(paths: &Vec) { -// for path in paths { -// ensure_file(path.as_ref().as_ref(), None); -// } -// } -// -// pub fn ensure_empty_dir>(path: P) -> io::Result<()> { -// let entries = fs::read_dir(path.as_ref())?; -// for entry in entries { -// let path = entry?.path(); -// if path.is_dir() { -// fs::remove_dir_all(&path)?; // 如果是目录,则递归删除 -// } else { -// fs::remove_file(&path)?; // 如果是文件,则直接删除 -// } -// } -// Ok(()) -// } -// -// pub fn setup_with_empty_workdir() { -// let test_dir = find_cargo_dir().join(TEST_DIR); -// ensure_empty_dir(&test_dir).unwrap(); -// setup_with_clean_mit(); -// } -// /// create file related to working directory pub fn ensure_file(path: impl AsRef, content: Option<&str>) { let path = path.as_ref(); @@ -152,26 +127,3 @@ pub fn ensure_file(path: impl AsRef, content: Option<&str>) { .unwrap(); } } -// -// pub fn ensure_no_file(path: &Path) { -// // 以测试目录为根目录,删除文件 -// if path.exists() { -// fs::remove_file(util::get_working_dir().unwrap().join(path)).unwrap(); -// } -// } -// -// /** 列出子文件夹 */ -// pub fn list_subdir(path: &Path) -> io::Result> { -// let mut files = Vec::new(); -// let path = path.to_absolute(); -// if path.is_dir() { -// for entry in fs::read_dir(path)? { -// let entry = entry?; -// let path = entry.path(); -// if path.is_dir() && path.file_name().unwrap_or_default() != util::ROOT_DIR { -// files.push(path) -// } -// } -// } -// Ok(files) -// } diff --git a/libra/src/utils/util.rs b/libra/src/utils/util.rs index 689939f2d..7b64cf427 100644 --- a/libra/src/utils/util.rs +++ b/libra/src/utils/util.rs @@ -200,7 +200,7 @@ pub fn calc_file_blob_hash(path: impl AsRef) -> io::Result { Ok(SHA1::from_type_and_data(ObjectType::Blob, &data)) } -/// List all files in the given dir and its subdir, except `.libra` +/// List all files in the given dir and its sub_dir, except `.libra` /// - input `path`: absolute path or relative path to the current dir /// - output: to workdir path pub fn list_files(path: &Path) -> io::Result> { @@ -214,7 +214,6 @@ pub fn list_files(path: &Path) -> io::Result> { let entry = entry?; let path = entry.path(); if path.is_dir() { - // subdir files.extend(list_files(&path)?); } else { files.push(to_workdir_path(&path)); @@ -224,7 +223,7 @@ pub fn list_files(path: &Path) -> io::Result> { Ok(files) } -/// list all files in the working dir(include subdir) +/// list all files in the working dir(include sub_dir) /// - output: to workdir path pub fn list_workdir_files() -> io::Result> { list_files(&working_dir()) diff --git a/mercury/src/internal/pack/cache.rs b/mercury/src/internal/pack/cache.rs index 7c4c1323b..06344a4da 100644 --- a/mercury/src/internal/pack/cache.rs +++ b/mercury/src/internal/pack/cache.rs @@ -59,7 +59,7 @@ impl Caches { match self.read_from_temp(hash) { Ok(x) => break x, Err(e) if e.kind() == io::ErrorKind::NotFound => { - sleep(std::time::Duration::from_millis(10)); //TODO 有没有更好办法 + sleep(std::time::Duration::from_millis(10)); continue; } Err(e) => return Err(e), // other error