-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0c3d41
commit 9b5dfdc
Showing
11 changed files
with
159 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ pub mod init; | |
pub mod switch; | ||
pub mod cat; | ||
pub mod delete; | ||
pub mod log; | ||
pub mod log; | ||
pub mod revert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::utils::{ | ||
create_fs_from_hash::create_fs, get_current_branch::get_current_branch, | ||
yaml_layouts::ConfigLayout, | ||
}; | ||
use std::{fs, io, path::Path}; | ||
|
||
pub fn revert(level: &usize, path: &String) -> io::Result<()> { | ||
let current_branch: Result<String, std::io::Error> = get_current_branch(); | ||
match current_branch { | ||
Ok(current_branch) => { | ||
let vault_path: &Path = Path::new(".vault"); | ||
let branch_path: std::path::PathBuf = vault_path.join(¤t_branch); | ||
let config_path: std::path::PathBuf = branch_path.join("config.yaml"); | ||
let content_bytes: Vec<u8> = fs::read(config_path).expect("Unable to read config.yaml"); | ||
let content: std::borrow::Cow<'_, str> = String::from_utf8_lossy(&content_bytes); | ||
let config_content: ConfigLayout = serde_yaml::from_str(&content).unwrap(); | ||
let commits: Vec<crate::utils::yaml_layouts::Commit> = config_content.commits; | ||
if let Some(commit) = commits.get(commits.len() - 1 - level) { | ||
let n_th_last_commit_hash: &String = &commit.hash; | ||
let _ = create_fs(n_th_last_commit_hash, path, ¤t_branch); | ||
} else { | ||
panic!("Level provided is out of bound!") | ||
} | ||
Ok(()) | ||
} | ||
Err(e) => panic!("Some error occurred: {e}"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::{fs::File, io, path::Path}; | ||
|
||
use crate::core::commit::Commit; | ||
|
||
use super::compress_zlib::decompress_zlib; | ||
|
||
pub fn create_fs(commit_hash: &String, path: &String, branch: &String) -> io::Result<()> { | ||
let dir_name: &str = &commit_hash[..2]; | ||
let file_name: &str = &commit_hash[2..]; | ||
let vault_path: &Path = Path::new(".vault"); | ||
let current_branch_path: std::path::PathBuf = vault_path.join(branch); | ||
let object_dir_path: std::path::PathBuf = current_branch_path.join("objects"); | ||
let hash_dir: std::path::PathBuf = object_dir_path.join(dir_name); | ||
let hash_file_path: std::path::PathBuf = hash_dir.join(file_name); | ||
let file: File = File::open(hash_file_path)?; | ||
let commit_string: String = decompress_zlib(file).unwrap(); | ||
let commit_object: Option<Commit> = Commit::get_commit_from_content(&commit_string); | ||
println!("{:?}", commit_object); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod get_current_branch; | |
pub mod hash; | ||
pub mod read_files; | ||
pub mod yaml_layouts; | ||
pub mod create_fs_from_hash; |