MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_verified_checkpoint

Function write_verified_checkpoint

atomic-cli/src/commands/git/checkpoint.rs:424–490  ·  view source on GitHub ↗

Re-observe the verified shim state and publish it as a version-2 checkpoint.

(
    root: &Path,
    input: VerifiedCheckpointInput<'_>,
)

Source from the content-addressed store, hash-verified

422
423/// Re-observe the verified shim state and publish it as a version-2 checkpoint.
424pub(crate) fn write_verified_checkpoint(
425 root: &Path,
426 input: VerifiedCheckpointInput<'_>,
427) -> Result<ShimCheckpoint, CheckpointError> {
428 let atomic = observe_atomic_view(root, input.view)?;
429 if atomic.state.as_str() != input.atomic_state {
430 return Err(CheckpointError::ObservedStateChanged {
431 field: "Atomic state",
432 expected: input.atomic_state.to_string(),
433 current: atomic.state,
434 });
435 }
436
437 let observation = observe_git(root)?;
438 let GitObservation::Repository(repository) = observation else {
439 return Err(CheckpointError::NoGit);
440 };
441 // CB-8A: Draft views stay detached at their projection commit (RFC
442 // §8.1); the checkpoint records a `None` symref for detached states so
443 // the workspace entry protocol keeps them aligned, exactly like the
444 // CB-7A anchor does for adopted ephemeral views.
445 let (symref, oid) = match &repository.head {
446 HeadObservation::Attached { symref, oid } => (Some(symref.clone()), *oid),
447 HeadObservation::Detached { oid } => (None, *oid),
448 _ => return Err(CheckpointError::UnsupportedHead),
449 };
450 let head_tree = repository
451 .head_tree_oid
452 .map(|oid| oid.to_string())
453 .ok_or(CheckpointError::UnsupportedHead)?;
454 if oid.to_string().as_str() != input.git_head {
455 return Err(CheckpointError::ObservedStateChanged {
456 field: "Git HEAD",
457 expected: input.git_head.to_string(),
458 current: oid.to_string(),
459 });
460 }
461 if head_tree.as_str() != input.git_tree {
462 return Err(CheckpointError::ObservedStateChanged {
463 field: "Git HEAD tree",
464 expected: input.git_tree.to_string(),
465 current: head_tree,
466 });
467 }
468
469 let checkpoint = ShimCheckpoint {
470 version: CHECKPOINT_VERSION,
471 view: atomic.view,
472 atomic_state: input.atomic_state.to_string(),
473 atomic_manifest_root: atomic.manifest_root,
474 git_head_symref: symref,
475 git_head: input.git_head.to_string(),
476 git_tree: input.git_tree.to_string(),
477 git_manifest_root: Some(ManifestRootEvidence::git_tree(input.git_tree)),
478 git_index_tree: repository.index.tree_oid.map(|oid| oid.to_string()),
479 git_index_digest: Some(repository.index.canonical_digest.0.clone()),
480 git_refs_digest: Some(repository.refs_digest.0.clone()),
481 git_admin: Some(GitAdminIdentity {

Calls 6

observe_atomic_viewFunction · 0.85
observe_gitFunction · 0.85
git_treeFunction · 0.85
write_checkpointFunction · 0.70
as_strMethod · 0.45
cloneMethod · 0.45