History

feat: Add support for hashes of different size (#279)

Even though right now, there is only Sha1, in future it's easy to support other hash sizes.

Sebastian Thiel committed 4 years ago

Commit 265b8ec1 parent bf620675 files · +52 −59Browse files

Showing the changes to git-commitgraph/src/file/commit.rs (1 of 5 files). Show all

Unified · Split

git-commitgraph/src/file/commit.rs+6−8
@@ -5,13 +5,11 @@ use std::{ · 4 unmodified lines
55 slice::Chunks,
66 };
77
8−use byteorder::{BigEndian, ByteOrder};
9−use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
10−
118 use crate::{
129 file::{self, File, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT},
1310 graph,
1411 };
12+use byteorder::{BigEndian, ByteOrder};
1513
1614 /// The error used in the [`file::commit`][self] module.
1715 #[derive(thiserror::Error, Debug)]
@@ -45,11 +43,11 @@ impl<'a> Commit<'a> { · 27 unmodified lines
4543 Commit {
4644 file,
4745 pos,
48− root_tree_id: git_hash::oid::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"),
49− parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])),
50− parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])),
51− generation: BigEndian::read_u32(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 12]) >> 2,
52− commit_timestamp: BigEndian::read_u64(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 16]) & 0x0003_ffff_ffff,
46+ root_tree_id: git_hash::oid::try_from(&bytes[..file.hash_len]).expect("hash bytes to be alright"),
47+ parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len..][..4])),
48+ parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len + 4..][..4])),
49+ generation: BigEndian::read_u32(&bytes[file.hash_len + 8..][..4]) >> 2,
50+ commit_timestamp: BigEndian::read_u64(&bytes[file.hash_len + 8..][..8]) & 0x0003_ffff_ffff,
5351 }
5452 }
5553