Validate a binding's change closure against the available objects. Checks, in order: 1. structural payload validation (version, ordering, OIDs, signer); 2. `closure_root` recomputation over the ordered changes; 3. the closure entry budget; 4. per-change quarantine through `source` (corruption fails closed); 5. dependency completeness: every dependency is inside the closure or resolvable through `
(
payload: &super::codec::GitStateBindingPayload,
source: &mut dyn ClosureChangeSource,
limits: &BindingPackLimits,
)
| 467 | /// Missing objects are *reported* (`missing`), never synthesized, so callers |
| 468 | /// can drive remote/pack fallback and report explicit incompleteness. |
| 469 | pub fn validate_binding_closure( |
| 470 | payload: &super::codec::GitStateBindingPayload, |
| 471 | source: &mut dyn ClosureChangeSource, |
| 472 | limits: &BindingPackLimits, |
| 473 | ) -> Result<ClosureValidation, BindingClosureError> { |
| 474 | payload |
| 475 | .validate() |
| 476 | .map_err(|error| BindingClosureError::InvalidBinding(error.to_string()))?; |
| 477 | |
| 478 | if payload.ordered_changes.len() > limits.max_closure_entries { |
| 479 | return Err(BindingClosureError::ClosureTooLarge { |
| 480 | limit: limits.max_closure_entries, |
| 481 | found: payload.ordered_changes.len(), |
| 482 | }); |
| 483 | } |
| 484 | if payload.closure_root != payload.compute_closure_root() { |
| 485 | return Err(BindingClosureError::ClosureRootMismatch); |
| 486 | } |
| 487 | |
| 488 | // Decode every ordered change through the source. |
| 489 | let mut changes: HashMap<Hash, Change> = HashMap::with_capacity(payload.ordered_changes.len()); |
| 490 | let mut missing: Vec<Hash> = Vec::new(); |
| 491 | for hash in &payload.ordered_changes { |
| 492 | match source.get(hash)? { |
| 493 | Some(change) => { |
| 494 | changes.insert(*hash, change); |
| 495 | } |
| 496 | None => missing.push(*hash), |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // Dependency completeness + cycle/depth over the closure-internal graph. |
| 501 | let mut external_deps = 0usize; |
| 502 | let mut internal_edges: HashMap<Hash, Vec<Hash>> = HashMap::with_capacity(changes.len()); |
| 503 | for (hash, change) in &changes { |
| 504 | let mut edges = Vec::new(); |
| 505 | for dep in change.dependencies() { |
| 506 | if changes.contains_key(dep) { |
| 507 | edges.push(*dep); |
| 508 | } else if !payload.ordered_changes.contains(dep) { |
| 509 | // Outside the binding's closure: legitimate only when some |
| 510 | // source (typically the local store) still provides it. |
| 511 | match source.get(dep)? { |
| 512 | Some(_) => external_deps += 1, |
| 513 | None => { |
| 514 | if !missing.contains(dep) { |
| 515 | missing.push(*dep); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | internal_edges.insert(*hash, edges); |
| 522 | } |
| 523 | |
| 524 | let depth = check_depth_and_cycles(&internal_edges, limits.max_closure_depth)?; |
| 525 | |
| 526 | Ok(ClosureValidation { |