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

Function checkpoint

atomic-agent/src/record/mod.rs:422–450  ·  view source on GitHub ↗
(
        git: &git2::Repository,
        state: &GitStateRef,
        template: &GitBoundaryCheckpoint,
    )

Source from the content-addressed store, hash-verified

420 return false;
421 };
422 fn checkpoint(
423 git: &git2::Repository,
424 state: &GitStateRef,
425 template: &GitBoundaryCheckpoint,
426 ) -> Option<GitBoundaryCheckpoint> {
427 let (oid, symref) = match &state.head {
428 GitHeadState::Attached { symref, oid } => (oid, Some(symref.clone())),
429 GitHeadState::Detached { oid } => (oid, None),
430 _ => return None,
431 };
432 let hex = |oid: &atomic_core::operation::GitObjectId| {
433 oid.as_bytes()
434 .iter()
435 .map(|b| format!("{b:02x}"))
436 .collect::<String>()
437 };
438 let mut checkpoint = template.clone();
439 checkpoint.head_oid = Some(hex(oid));
440 checkpoint.head_symref = symref;
441 // Before publication the index may contain partial staging. HEAD's
442 // tree must come from its commit, independently of the index tree.
443 checkpoint.head_tree = Some(
444 git.find_commit(git2::Oid::from_bytes(oid.as_bytes()).ok()?)
445 .ok()?
446 .tree_id()
447 .to_string(),
448 );
449 Some(checkpoint)
450 }
451 let Ok(git) = git2::Repository::discover(repo.root()) else {
452 return false;
453 };

Callers 1

projection_journaledFunction · 0.70

Calls 5

hexFunction · 0.70
cloneMethod · 0.45
iterMethod · 0.45
as_bytesMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected