Resolve what a Git SHA lookup may conclude (checked cache contract). The index and stored bindings only ever *shortlist* candidates; every returned binding is fully re-verified (cryptography + live Git content), so injected missing, stale, ambiguous, or malicious index entries cannot change the outcome relative to a cold cache.
(
&self,
git: &git2::Repository,
commit: &atomic_core::operation::GitObjectId,
)
| 547 | /// content), so injected missing, stale, ambiguous, or malicious index |
| 548 | /// entries cannot change the outcome relative to a cold cache. |
| 549 | pub fn resolve_git_sha( |
| 550 | &self, |
| 551 | git: &git2::Repository, |
| 552 | commit: &atomic_core::operation::GitObjectId, |
| 553 | ) -> Result<GitShaResolution, RepositoryError> { |
| 554 | // Candidates from stored bindings whose bound commit matches. |
| 555 | let mut candidates: Vec<GitStateBinding> = Vec::new(); |
| 556 | |
| 557 | for id in self.binding_ids()? { |
| 558 | let Ok(Some(binding)) = self.load_binding(&id) else { |
| 559 | continue; |
| 560 | }; |
| 561 | let Ok(bound_commit) = binding.payload().git_commit.to_git_object_id() else { |
| 562 | continue; |
| 563 | }; |
| 564 | if &bound_commit == commit { |
| 565 | candidates.push(binding); |
| 566 | } |
| 567 | } |
| 568 | // A cache row may also tie the SHA to a change; when a stored |
| 569 | // binding's closure contains exactly that change, it is a candidate. |
| 570 | // The row itself is never adoption evidence — every candidate is |
| 571 | // still fully re-verified below, which is what makes the cache |
| 572 | // checked rather than authoritative. |
| 573 | let sha = crate::repository::synthesis::git_oid_hex(commit); |
| 574 | let index_candidate = self.raw_git_sha_row(&sha)?.is_some(); |
| 575 | if candidates.is_empty() { |
| 576 | if let Some(change) = self.raw_git_sha_row(&sha)? { |
| 577 | for id in self.binding_ids()? { |
| 578 | let Ok(Some(binding)) = self.load_binding(&id) else { |
| 579 | continue; |
| 580 | }; |
| 581 | if binding.payload().ordered_changes.contains(&change) { |
| 582 | candidates.push(binding); |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | if candidates.is_empty() { |
| 588 | return Ok(GitShaResolution::Cold); |
| 589 | } |
| 590 | for binding in &candidates { |
| 591 | if verify_binding_cryptography(binding).is_err() { |
| 592 | continue; |
| 593 | } |
| 594 | if verify_binding_content(git, binding).is_err() { |
| 595 | continue; |
| 596 | } |
| 597 | return Ok(GitShaResolution::VerifiedBinding { |
| 598 | binding: binding.clone(), |
| 599 | index_candidate, |
| 600 | }); |
| 601 | } |
| 602 | Ok(GitShaResolution::Unresolved { |
| 603 | detail: format!( |
| 604 | "{} stored binding(s) name commit {} and all failed verification", |
| 605 | candidates.len(), |
| 606 | crate::repository::synthesis::git_oid_hex(commit) |