Build the hashed foreign-commit fact record for `parsed` (review blocker 6). The raw object bytes come from Phase 1's parse ([`ParsedCommit::raw_object`]); hex encoding keeps the JSON record byte-safe for non-UTF-8 identity data.
(parsed: &ParsedCommit)
| 298 | /// ([`ParsedCommit::raw_object`]); hex encoding keeps the JSON record |
| 299 | /// byte-safe for non-UTF-8 identity data. |
| 300 | pub(crate) fn foreign_commit_facts(parsed: &ParsedCommit) -> CliResult<Vec<u8>> { |
| 301 | let algorithm = git_algorithm_for_sha(&parsed.git_sha)?; |
| 302 | let record = ForeignCommitFacts { |
| 303 | format: FOREIGN_COMMIT_FACTS_FORMAT, |
| 304 | commit: tagged_oid_hex(&git_object_id_for_sha(algorithm, &parsed.git_sha)?), |
| 305 | tree: tagged_oid_hex(&git_object_id(algorithm, parsed.tree_oid)?), |
| 306 | algorithm: git_algorithm_label(algorithm).to_string(), |
| 307 | parents: parsed |
| 308 | .parent_oids |
| 309 | .iter() |
| 310 | .map(|oid| { |
| 311 | let tagged = git_object_id(algorithm, *oid)?; |
| 312 | Ok(tagged_oid_hex(&tagged)) |
| 313 | }) |
| 314 | .collect::<CliResult<Vec<_>>>()?, |
| 315 | author: ForeignSignatureFacts { |
| 316 | name: parsed.metadata.author_name.clone(), |
| 317 | email: parsed.metadata.author_email.clone(), |
| 318 | time: parsed.metadata.author_time, |
| 319 | time_offset_seconds: parsed.metadata.author_time_offset_seconds, |
| 320 | name_raw_hex: hex_bytes(Some(&parsed.metadata.author_name_raw)), |
| 321 | email_raw_hex: hex_bytes(parsed.metadata.author_email_raw.as_deref()), |
| 322 | }, |
| 323 | committer: CommitterFacts { |
| 324 | name: parsed.metadata.committer_name.clone(), |
| 325 | email: parsed.metadata.committer_email.clone(), |
| 326 | time: parsed.metadata.committer_time, |
| 327 | time_offset_seconds: parsed.metadata.committer_time_offset_seconds, |
| 328 | name_raw_hex: hex_bytes(Some(&parsed.metadata.committer_name_raw)), |
| 329 | email_raw_hex: hex_bytes(parsed.metadata.committer_email_raw.as_deref()), |
| 330 | }, |
| 331 | raw_object_hex: hex_bytes(Some(&parsed.raw_object)), |
| 332 | }; |
| 333 | serde_json::to_vec(&record).map_err(|e| CliError::Internal(e.into())) |
| 334 | } |
| 335 | |
| 336 | /// Hex-encode raw bytes (`""` when absent) for the hashed fact records. |
| 337 | pub(crate) fn hex_bytes(bytes: Option<&[u8]>) -> String { |
no test coverage detected