Skip to content

Commit f2b07c0

Browse files
committed
add fallible gix_object::try_compute_hash for migration
1 parent 5095f44 commit f2b07c0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gix-object/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,17 @@ pub fn compute_hash(hash_kind: gix_hash::Kind, object_kind: Kind, data: &[u8]) -
412412
hasher.finalize()
413413
}
414414

415+
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
416+
pub fn try_compute_hash(
417+
hash_kind: gix_hash::Kind,
418+
object_kind: Kind,
419+
data: &[u8],
420+
) -> 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()
424+
}
425+
415426
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its data read from `stream`
416427
/// which has to yield exactly `stream_len` bytes.
417428
/// Use `progress` to learn about progress in bytes processed and `should_interrupt` to be able to abort the operation

0 commit comments

Comments
 (0)