Skip to content

Commit

Permalink
Completed impl for Blob
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhexists committed Dec 21, 2023
1 parent 9b5dfdc commit 440cbab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/core/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ impl Blob {
}

fn parse_vec_of_contents(blob_content: &Vec<&str>) -> Blob {
todo!()
let filetype: FileTypes = match blob_content[1] {
"UTF" => FileTypes::Utf8,
"NonUTF" => FileTypes::NonUTF8,
_ => panic!("Unknown file type of Blob"),
};
let content: String = blob_content[3].to_string();
let content_size: Result<i32, std::num::ParseIntError> = blob_content[2].parse::<i32>();
match content_size {
Ok(content_size) => Blob {
content,
is_utf8: filetype,
content_size,
},
Err(e) => panic!("{e}"),
}
}
}
8 changes: 4 additions & 4 deletions src/core/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Commit {
date_time: String,
message: String,
author: String,
commit_hash: String,
pub commit_hash: String,
parent: Option<String>,
}

Expand Down Expand Up @@ -75,14 +75,14 @@ impl Commit {
content
}

pub fn get_commit_from_content(commit_content: &String) -> Option<Commit> {
pub fn get_commit_from_content(commit_content: &String) -> Commit {
let break_by_new_line_char: Vec<&str> = commit_content.split("\n").collect();
let is_valid_commit: bool = Commit::check_valid_content(&break_by_new_line_char);
if is_valid_commit {
let commit_object: Commit = Commit::parse_vec_of_contents(&break_by_new_line_char);
return Some(commit_object)
return commit_object;
}
None
panic!("Unable to get commit content!")
}

fn check_valid_content(contents: &Vec<&str>) -> bool {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/create_fs_from_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub fn create_fs(commit_hash: &String, path: &String, branch: &String) -> io::Re
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);
let commit_object: Commit = Commit::get_commit_from_content(&commit_string);
let root_dir_hash: String = commit_object.commit_hash;
Ok(())
}

0 comments on commit 440cbab

Please sign in to comment.