恢复index更改

This commit is contained in:
mrbeanc
2023-12-27 16:19:02 +08:00
committed by HouXiaoxuan
parent 7b1e344d32
commit 2106951787
4 changed files with 30 additions and 25 deletions

View File

@@ -55,7 +55,7 @@ pub struct Index {
impl Index {
/// 从index文件加载
pub fn new() -> Index {
fn new() -> Index {
let mut index = Index::default();
index.load();
return index;
@@ -67,7 +67,7 @@ impl Index {
unsafe { &mut INSTANCE }
}
/// 重置index 从文件重新加载,主要用于测试,防止单例模式的影响
/// 重置index主要用于测试防止单例模式的影响
pub fn reload() {
let index = Index::get_instance();
index.load();
@@ -224,14 +224,14 @@ mod tests {
#[test]
fn test_load() {
test_util::setup_test_with_clean_mit();
let index = Index::new();
let index = Index::get_instance();
println!("{:?}", index);
}
#[test]
fn test_save() {
test_util::setup_test_with_clean_mit();
let mut index = Index::new();
let index = Index::get_instance();
let path = PathBuf::from("../mit_test_storage/.mit/HEAD"); //测试../相对路径的处理
index.add(path.clone(), FileMetaData::new(&Blob::new(&path), &path));

View File

@@ -165,7 +165,7 @@ mod test {
#[test]
fn test_new() {
test_util::setup_test_with_clean_mit();
let mut index = Index::new();
let index = Index::get_instance();
for test_file in vec!["b.txt", "mit_src/a.txt", "test/test.txt"] {
let test_file = PathBuf::from(test_file);
test_util::ensure_test_file(&test_file, None);
@@ -181,7 +181,7 @@ mod test {
#[test]
fn test_load() {
test_util::setup_test_with_clean_mit();
let mut index = Index::new();
let index = Index::get_instance();
let test_files = vec!["b.txt", "mit_src/a.txt"];
for test_file in test_files.clone() {
let test_file = PathBuf::from(test_file);
@@ -201,7 +201,7 @@ mod test {
#[test]
fn test_get_recursive_file_entries() {
test_util::setup_test_with_clean_mit();
let mut index = Index::new();
let index = Index::get_instance();
let mut test_files = vec![PathBuf::from("b.txt"), PathBuf::from("mit_src/a.txt")];
for test_file in test_files.clone() {
test_util::ensure_test_file(&test_file, None);
@@ -229,7 +229,7 @@ mod test {
#[test]
fn test_get_recursive_blobs() {
test_util::setup_test_with_clean_mit();
let mut index = Index::new();
let index = Index::get_instance();
let test_files = vec!["b.txt", "mit_src/a.txt"];
let mut test_blobs = vec![];
for test_file in test_files.clone() {