Skip to content

Commit c000294

Browse files
committed
specify the hash to create with 'hash::bytes_of_file'
1 parent c5f6b45 commit c000294

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

git-features/src/hash.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ pub use crc::crc32::checksum_ieee as crc32;
4646
pub fn bytes_of_file(
4747
path: impl AsRef<std::path::Path>,
4848
num_bytes_from_start: usize,
49+
kind: git_object::HashKind,
4950
progress: &mut impl crate::progress::Progress,
5051
) -> std::io::Result<git_object::owned::Id> {
51-
let mut hasher = crate::hash::Sha1::default();
52+
let mut hasher = match kind {
53+
git_object::HashKind::Sha1 => crate::hash::Sha1::default(),
54+
};
5255
let start = std::time::Instant::now();
5356
// init progress before the possibility for failure, as convenience in case people want to recover
5457
progress.init(Some(num_bytes_from_start), crate::progress::bytes());

git-odb/src/pack/data/verify.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::pack::data::File;
22
use git_features::progress::Progress;
3-
use git_object::{owned, SHA1_SIZE};
3+
use git_object::{owned, HashKind, SHA1_SIZE};
44

55
#[derive(thiserror::Error, Debug)]
66
pub enum Error {
@@ -17,17 +17,18 @@ impl File {
1717
}
1818
pub fn verify_checksum(&self, mut progress: impl Progress) -> Result<owned::Id, Error> {
1919
let right_before_trailer = self.data.len() - SHA1_SIZE;
20-
let actual = match git_features::hash::bytes_of_file(&self.path, right_before_trailer, &mut progress) {
21-
Ok(id) => id,
22-
Err(_io_err) => {
23-
let start = std::time::Instant::now();
24-
let mut hasher = git_features::hash::Sha1::default();
25-
hasher.update(&self.data[..right_before_trailer]);
26-
progress.inc_by(right_before_trailer);
27-
progress.show_throughput(start);
28-
owned::Id::new_sha1(hasher.digest())
29-
}
30-
};
20+
let actual =
21+
match git_features::hash::bytes_of_file(&self.path, right_before_trailer, HashKind::Sha1, &mut progress) {
22+
Ok(id) => id,
23+
Err(_io_err) => {
24+
let start = std::time::Instant::now();
25+
let mut hasher = git_features::hash::Sha1::default();
26+
hasher.update(&self.data[..right_before_trailer]);
27+
progress.inc_by(right_before_trailer);
28+
progress.show_throughput(start);
29+
owned::Id::new_sha1(hasher.digest())
30+
}
31+
};
3132

3233
let expected = self.checksum();
3334
if actual == expected {

git-odb/src/pack/index/verify.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use git_features::progress::{self, Progress};
33
use git_object::{
44
borrowed,
55
bstr::{BString, ByteSlice},
6-
owned, SHA1_SIZE,
6+
owned, HashKind, SHA1_SIZE,
77
};
88

99
#[derive(thiserror::Error, Debug)]
@@ -51,7 +51,12 @@ impl index::File {
5151

5252
pub fn verify_checksum(&self, mut progress: impl Progress) -> Result<owned::Id, Error> {
5353
let data_len_without_trailer = self.data.len() - SHA1_SIZE;
54-
let actual = match git_features::hash::bytes_of_file(&self.path, data_len_without_trailer, &mut progress) {
54+
let actual = match git_features::hash::bytes_of_file(
55+
&self.path,
56+
data_len_without_trailer,
57+
HashKind::Sha1,
58+
&mut progress,
59+
) {
5560
Ok(id) => id,
5661
Err(_io_err) => {
5762
let start = std::time::Instant::now();

0 commit comments

Comments
 (0)