(kind: ObjectType, content: &[u8])
| 598 | } |
| 599 | |
| 600 | pub(super) fn git_object_oid(kind: ObjectType, content: &[u8]) -> GitObjectId { |
| 601 | use sha1::Digest as _; |
| 602 | let mut hasher = sha1::Sha1::new(); |
| 603 | let header = format!("{} {}\0", object_kind_name(kind), content.len()); |
| 604 | hasher.update(header.as_bytes()); |
| 605 | hasher.update(content); |
| 606 | let bytes: [u8; 20] = hasher.finalize().into(); |
| 607 | GitObjectId::new(GitHashAlgorithm::Sha1, bytes.to_vec()) |
| 608 | .expect("a SHA-1 digest is a valid 20-byte object id") |
| 609 | } |
| 610 | |
| 611 | fn object_kind_name(kind: ObjectType) -> &'static str { |
| 612 | match kind { |
no test coverage detected