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
5 slice::Chunks,5 slice::Chunks,
6};6};
7 7
8use byteorder::{BigEndian, ByteOrder};
9use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
10
11use crate::{8use crate::{
12 file::{self, File, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT},9 file::{self, File, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT},
13 graph,10 graph,
14};11};
12use byteorder::{BigEndian, ByteOrder};
15 13
16/// The error used in the [`file::commit`][self] module.14/// The error used in the [`file::commit`][self] module.
17#[derive(thiserror::Error, Debug)]15#[derive(thiserror::Error, Debug)]
@@ -45,11 +43,11 @@ impl<'a> Commit<'a> { · 27 unmodified lines
45 Commit {43 Commit {
46 file,44 file,
47 pos,45 pos,
48 root_tree_id: git_hash::oid::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"),46 root_tree_id: git_hash::oid::try_from(&bytes[..file.hash_len]).expect("hash bytes to be alright"),
49 parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])),47 parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len..][..4])),
50 parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])),48 parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len + 4..][..4])),
51 generation: BigEndian::read_u32(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 12]) >> 2,49 generation: BigEndian::read_u32(&bytes[file.hash_len + 8..][..4]) >> 2,
52 commit_timestamp: BigEndian::read_u64(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 16]) & 0x0003_ffff_ffff,50 commit_timestamp: BigEndian::read_u64(&bytes[file.hash_len + 8..][..8]) & 0x0003_ffff_ffff,
53 }51 }
54 }52 }
55 53