(
algorithm: GitHashAlgorithm,
kind: GitObjectKind,
bytes: &[u8],
)
| 1156 | } |
| 1157 | |
| 1158 | pub(super) fn git_object_id( |
| 1159 | algorithm: GitHashAlgorithm, |
| 1160 | kind: GitObjectKind, |
| 1161 | bytes: &[u8], |
| 1162 | ) -> Result<GitObjectId, ProjectTreeError> { |
| 1163 | let kind = match kind { |
| 1164 | GitObjectKind::Blob => "blob", |
| 1165 | GitObjectKind::Tree => "tree", |
| 1166 | }; |
| 1167 | let header = format!("{kind} {}\0", bytes.len()); |
| 1168 | let digest = match algorithm { |
| 1169 | GitHashAlgorithm::Sha1 => { |
| 1170 | let mut hasher = sha1::Sha1::new(); |
| 1171 | hasher.update(header.as_bytes()); |
| 1172 | hasher.update(bytes); |
| 1173 | hasher.finalize().to_vec() |
| 1174 | } |
| 1175 | GitHashAlgorithm::Sha256 => { |
| 1176 | let mut hasher = sha2::Sha256::new(); |
| 1177 | hasher.update(header.as_bytes()); |
| 1178 | hasher.update(bytes); |
| 1179 | hasher.finalize().to_vec() |
| 1180 | } |
| 1181 | }; |
| 1182 | GitObjectId::new(algorithm, digest) |
| 1183 | .map_err(|error| ProjectTreeError::GitObjectId(error.to_string())) |
| 1184 | } |
| 1185 | |
| 1186 | impl Repository { |
| 1187 | /// Build the canonical repository manifest and Git tree from recorded view state. |
no test coverage detected