Skip to content

Commit c526811

Browse files
committed
remove byteorder dependency from git-commitgraph (#293)
This is now sufficiently well implemented in the standard library.
1 parent 826ca0c commit c526811

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-commitgraph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ git-hash = { version ="^0.8.0", path = "../git-hash" }
2121
git-chunk = { version ="^0.2.0", path = "../git-chunk" }
2222

2323
bstr = { version = "0.2.13", default-features = false, features = ["std"] }
24-
byteorder = "1.2.3"
2524
memmap2 = "0.5.0"
2625
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
2726
thiserror = "1.0.26"

git-commitgraph/src/file/commit.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use std::{
55
slice::Chunks,
66
};
77

8-
use byteorder::{BigEndian, ByteOrder};
9-
108
use crate::{
119
file::{self, File, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT},
1210
graph,
@@ -38,17 +36,23 @@ pub struct Commit<'a> {
3836
root_tree_id: &'a git_hash::oid,
3937
}
4038

39+
#[inline]
40+
fn read_u32(b: &[u8]) -> u32 {
41+
u32::from_be_bytes(b.try_into().unwrap())
42+
}
43+
4144
impl<'a> Commit<'a> {
4245
pub(crate) fn new(file: &'a File, pos: file::Position) -> Self {
4346
let bytes = file.commit_data_bytes(pos);
4447
Commit {
4548
file,
4649
pos,
4750
root_tree_id: git_hash::oid::from_bytes_unchecked(&bytes[..file.hash_len]),
48-
parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len..][..4])),
49-
parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[file.hash_len + 4..][..4])),
50-
generation: BigEndian::read_u32(&bytes[file.hash_len + 8..][..4]) >> 2,
51-
commit_timestamp: BigEndian::read_u64(&bytes[file.hash_len + 8..][..8]) & 0x0003_ffff_ffff,
51+
parent1: ParentEdge::from_raw(read_u32(&bytes[file.hash_len..][..4])),
52+
parent2: ParentEdge::from_raw(read_u32(&bytes[file.hash_len + 4..][..4])),
53+
generation: read_u32(&bytes[file.hash_len + 8..][..4]) >> 2,
54+
commit_timestamp: u64::from_be_bytes(bytes[file.hash_len + 8..][..8].try_into().unwrap())
55+
& 0x0003_ffff_ffff,
5256
}
5357
}
5458

@@ -173,7 +177,7 @@ impl<'a> Iterator for ParentIterator<'a> {
173177
},
174178
ParentIteratorState::Extra(mut chunks) => {
175179
if let Some(chunk) = chunks.next() {
176-
let extra_edge = BigEndian::read_u32(chunk);
180+
let extra_edge = read_u32(chunk);
177181
match ExtraEdge::from_raw(extra_edge) {
178182
ExtraEdge::Internal(pos) => {
179183
self.state = ParentIteratorState::Extra(chunks);

git-commitgraph/src/file/init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
};
55

66
use bstr::ByteSlice;
7-
use byteorder::{BigEndian, ByteOrder};
87
use memmap2::Mmap;
98

109
use crate::file::{
@@ -249,7 +248,7 @@ impl TryFrom<&Path> for File {
249248
fn read_fan(d: &[u8]) -> ([u32; FAN_LEN], usize) {
250249
let mut fan = [0; FAN_LEN];
251250
for (c, f) in d.chunks(4).zip(fan.iter_mut()) {
252-
*f = BigEndian::read_u32(c);
251+
*f = u32::from_be_bytes(c.try_into().unwrap());
253252
}
254253
(fan, FAN_LEN * 4)
255254
}

0 commit comments

Comments
 (0)