Skip to content

Commit

Permalink
残りもconcatできた
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Apr 17, 2024
1 parent 672f967 commit 7193b43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ fn update_index(file_names: &[PathBuf], hash_list: &[String]) -> anyhow::Result<
let group_id = &metadata.st_gid().to_be_bytes();
let file_size = &metadata.st_size().to_be_bytes()[4..8];
let oid = &hash_list[index];
let decoded_oid = hex::decode(oid)?;
let decoded_oid_slice = decoded_oid.as_slice();
// TODO: 正しく計算
let flags = &new_file_name.as_os_str().len().to_be_bytes()[6..8];
let path = new_file_name.to_path_buf();

let mut content: Vec<u8> = [
change_time,
Expand All @@ -183,17 +188,12 @@ fn update_index(file_names: &[PathBuf], hash_list: &[String]) -> anyhow::Result<
user_id,
group_id,
file_size,
decoded_oid_slice,
flags,
path.as_os_str().as_bytes(),
]
.concat();

let decoded_oid = hex::decode(oid)?;
// TODO: 正しく計算
let flags = &new_file_name.to_str().unwrap().len().to_be_bytes()[6..8];
let path = new_file_name.to_path_buf();

content.extend_from_slice(&decoded_oid);
content.extend_from_slice(flags);
content.extend_from_slice(path.as_os_str().as_bytes());
let padding = 4 - (content.len() % 4);
content.resize(content.len() + padding, 0);

Expand All @@ -210,7 +210,7 @@ fn update_index(file_names: &[PathBuf], hash_list: &[String]) -> anyhow::Result<
};

// header
let signature = "DIRC".as_bytes();
let signature = b"DIRC";
let version = &2u32.to_be_bytes();
let entrie_count = &merged_entries.len().to_be_bytes()[4..8];

Expand Down
3 changes: 1 addition & 2 deletions src/command/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ fn generate_commit_object(tree_hash: String, message: String) -> anyhow::Result<
author,
commiter,
message,
size: _,
hash: _,
..
} = &commit;
let parents: String = parents.iter().map(|p| format!("\nparent {p}")).join("");

Expand Down

0 comments on commit 7193b43

Please sign in to comment.