Skip to content

Commit b5ac93a

Browse files
committed
change!: make gix_object::compute_hash fallible
`compute_stream_hash` is already fallible, so we don’t want to keep the `try_*` prefix on the fallible API.
1 parent fbf6cc8 commit b5ac93a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gix-object/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,14 @@ fn object_hasher(hash_kind: gix_hash::Kind, object_kind: Kind, object_size: u64)
406406

407407
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
408408
#[doc(alias = "hash_object", alias = "git2")]
409-
pub fn compute_hash(hash_kind: gix_hash::Kind, object_kind: Kind, data: &[u8]) -> gix_hash::ObjectId {
409+
pub fn compute_hash(
410+
hash_kind: gix_hash::Kind,
411+
object_kind: Kind,
412+
data: &[u8],
413+
) -> Result<gix_hash::ObjectId, gix_hash::hasher::Error> {
410414
let mut hasher = object_hasher(hash_kind, object_kind, data.len() as u64);
411415
hasher.update(data);
412-
hasher.finalize()
416+
hasher.try_finalize()
413417
}
414418

415419
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
@@ -418,9 +422,7 @@ pub fn try_compute_hash(
418422
object_kind: Kind,
419423
data: &[u8],
420424
) -> Result<gix_hash::ObjectId, gix_hash::hasher::Error> {
421-
let mut hasher = object_hasher(hash_kind, object_kind, data.len() as u64);
422-
hasher.update(data);
423-
hasher.try_finalize()
425+
compute_hash(hash_kind, object_kind, data)
424426
}
425427

426428
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its data read from `stream`

0 commit comments

Comments
 (0)