Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"venus",
"ceres",
"libra",
"scorpio",
]
exclude = ["craft"]
resolver = "1"
Expand Down
6 changes: 3 additions & 3 deletions libra/src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use crate::utils::{path, util};

#[derive(Parser, Debug)]
pub struct AddArgs {
/// <pathspec>... files & dir to add content from.
/// pathspec... files & dir to add content from.
#[clap(required = false)]
pub pathspec: Vec<String>,

/// 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.
/// 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 <pathspec> 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,

Expand Down
24 changes: 12 additions & 12 deletions libra/src/command/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct BranchArgs {
#[clap(short = 'D', long, group = "sub")]
delete: Option<String>,

/// Set up <current branch>'s tracking information
/// Set up current branch's tracking information
#[clap(short = 'u', long, group = "sub")]
set_upstream_to: Option<String>,

Expand Down Expand Up @@ -187,23 +187,23 @@ async fn list_branches(remotes: bool) {
}

pub async fn get_target_commit(branch_or_commit: &str) -> Result<SHA1, Box<dyn std::error::Error>> {
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)
}
}

Expand Down Expand Up @@ -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);
}

{
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions libra/src/command/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ 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
}
}
}
}

#[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(),
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
10 changes: 5 additions & 5 deletions libra/src/command/index_pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BigEndian>(cnt)?;
fan_out.write_u32::<BigEndian>(cnt)?;
i += 1;
}
cnt += 1;
}
// fill the rest
loop {
fanout.write_u32::<BigEndian>(cnt)?;
fan_out.write_u32::<BigEndian>(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.
Expand Down
8 changes: 4 additions & 4 deletions libra/src/command/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ async fn lca_commit(lhs: &Commit, rhs: &Commit) -> Option<Commit> {
}
}

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());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libra/src/internal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions libra/src/internal/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DatabaseConnection> {
Expand All @@ -108,7 +108,7 @@ pub async fn create_database(db_path: &str) -> io::Result<DatabaseConnection> {
)
})?;

// 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(
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion libra/src/internal/protocol/https_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions libra/src/utils/path_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P, U>(&self, paths: U) -> bool
where
Expand Down
48 changes: 0 additions & 48 deletions libra/src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,6 @@ pub fn init_logger() {
.unwrap();
}

// pub fn ensure_files<T: AsRef<str>>(paths: &Vec<T>) {
// for path in paths {
// ensure_file(path.as_ref().as_ref(), None);
// }
// }
//
// pub fn ensure_empty_dir<P: AsRef<Path>>(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<Path>, content: Option<&str>) {
let path = path.as_ref();
Expand All @@ -152,26 +127,3 @@ pub fn ensure_file(path: impl AsRef<Path>, 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<Vec<PathBuf>> {
// 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)
// }
5 changes: 2 additions & 3 deletions libra/src/utils/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn calc_file_blob_hash(path: impl AsRef<Path>) -> io::Result<SHA1> {
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<Vec<PathBuf>> {
Expand All @@ -214,7 +214,6 @@ pub fn list_files(path: &Path) -> io::Result<Vec<PathBuf>> {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
// subdir
files.extend(list_files(&path)?);
} else {
files.push(to_workdir_path(&path));
Expand All @@ -224,7 +223,7 @@ pub fn list_files(path: &Path) -> io::Result<Vec<PathBuf>> {
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<Vec<PathBuf>> {
list_files(&working_dir())
Expand Down
6 changes: 3 additions & 3 deletions mercury/src/internal/pack/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<usize>() + std::mem::size_of::<SHA1>())
+ self.hash_set.capacity() * (std::mem::size_of::<SHA1>())
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions mercury/src/internal/pack/cache_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: HeapSize + Serialize + for<'a> Deserialize<'a> + Send + Sync + 'static> ArcWrapperBounds for T {}

/// !Implementing encapsulation of Arc<T> to enable third-party Trait HeapSize implementation for the Arc type
/// !Because of use Arc<T> 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<T: ArcWrapperBounds> {
pub data: Arc<T>,
complete_signal: Arc<AtomicBool>,
Expand Down